Edit: just to be clear, I will not doubt the jQuery awesomeness. I use it everywhere. I just don’t understand the benefits of using Widgets over regular js objects that use jQuery functionality.
I recently had to use some jQuery widgets in an application I'm working on, and I find them very unintuitive / ugly. There seem to be a lot of conventions to learn that don't really add any value, and the syntax does not take into account intellisense or simple refactoring.
Don't get me wrong, I use jQuery all the time and I hate life without it, just not seeing the value in the widget convention. I am sure that I do not have enough sense, because they are so common, so please tell me. Why do people create jQuery widgets instead of regular js objects?
Simplified procedure example:
Regular Javascript Object:
var foo = new MyDomain.MyObject('#mySpecialInput', options)
foo.render();
foo.value = 5;
foo.multiplyBy(2);
foo.change(function(){
alert('it changed');
}
JQuery Widget:
var $foo = $('#mySpecialInput');
$foo.myWidget(options);
$foo.myWidget('option', 'value', 5);
$foo.myWidget('multiplyBy', 2);
$foo.bind('myWidgetChange', function(){
alert('it changed');
}
source
share