javascript - Passing string parameter into constructor to call function -
I came to this programming style where: instead of calling directly an object method, they have a string in their constructor method If you pass, constructor method then check this string and call the function associate with it.
function MySimpleObject (option) {if (optionof option === 'string') {pluginMethods [String] .apply (this, logic); } Else {init (); }}
This function is being used with jQuery as a lot of detail.
jQuery.fn.extend ({simpleObj: MySimpleObject});
I really appreciate it if someone can highlight me on this.
This gives the following style of programming, which is used by jQuery UI for example:
$ ('selector'). Datepicker ('option', 'option-name', 'option -value');
If you do not call .datepicker ()
with no argument or an object, then this date initiates the picture when the first argument is a string, then This is a call to datepicker for a method. This approach is used for all jQuery UI widgets, and many other jQuery plugins are also similar.
Comments
Post a Comment