what does options mean ???
|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
what does options mean ???I am looking through some previous made code and I notice a special varible called options. I suppose it special because my html editor gives it a purple color that stands out as if its a predefined varible. the code looks like something below
$('#begin').click(function(){ $('#log').val('') $('#display').val('') log('Started recording: ' + duration + 'ms') $.Events({ duration: duration }, function(){ $('#display').val(this.exportJSON()) log('Finished recording') }) }) // Then the plug in receives it like this $.Events = function(options, callback) { if (callback) options.finished = callback return (new Eventer(options)).start() } // I understand that you can pass variables in a parameter through an array. is this options keyword a way to present the values in the the array ??? If so then where did the variable called 'finished' come from. can you add more varibles to the keyword 'options' ??? |
|
|
Re: what does options mean ???$.Events = function(options, callback)
This defines a function called $.Events that takes 2 parameters. When you see a parameter named options, you can usually assume that it represents a hash. When you see a param named callback, it means that the function expects either the name of some function or an anonymous function block. $.Events({ duration: duration }, function(){ ...}); This is an example of the function being called. The 2 parameters passed are a hash ( { duration: duration } ) and an anonymous function. So, if you wish to pass more/different options, include them in the hash that's passed here, eg: $.Events({ duration: duration, foo: bar }, function(){ ...}); On Sat, Oct 31, 2009 at 6:50 PM, numerical25 <numerical25@...> wrote: > > I am looking through some previous made code and I notice a special varible > called options. I suppose it special because my html editor gives it a > purple color that stands out as if its a predefined varible. the code looks > like something below > > $('#begin').click(function(){ > $('#log').val('') > $('#display').val('') > log('Started recording: ' + duration + 'ms') > > $.Events({ duration: duration }, function(){ > $('#display').val(this.exportJSON()) > log('Finished recording') > }) > }) > > > // Then the plugin recieves it like this > > $.Events = function(options, callback) { > if (callback) options.finished = callback > return (new Eventer(options)).start() > } > > // I understand that you can pass variables in a parameter through an array. > is this options keyword a way to present the values in the the array ??? > > If so then where did this finished varible come from. can you add more > varibles to the keyword 'options' ??? > -- > View this message in context: http://old.nabble.com/what-does-options-mean-----tp26146827s27240p26146827.html > Sent from the jQuery General Discussion mailing list archive at Nabble.com. > > |
|
|
Re: what does options mean ???I'd suggest reading this article
http://www.learningjquery.com/2007/10/a-plugin-development-pattern heck, he even uses "options" for the name, and that probably is not coincidence as many people follow Mike's suggested pattern On Oct 31, 6:50 pm, numerical25 <numerica...@...> wrote: > I am looking through some previous made code and I notice a special varible > called options. I suppose it special because my html editor gives it a > purple color that stands out as if its a predefined varible. the code looks > like something below > > $('#begin').click(function(){ > $('#log').val('') > $('#display').val('') > log('Started recording: ' + duration + 'ms') > > $.Events({ duration: duration }, function(){ > $('#display').val(this.exportJSON()) > log('Finished recording') > }) > }) > > // Then the plugin recieves it like this > > $.Events = function(options, callback) { > if (callback) options.finished = callback > return (new Eventer(options)).start() > } > > // I understand that you can pass variables in a parameter through an array. > is this options keyword a way to present the values in the the array ??? > > If so then where did this finished varible come from. can you add more > varibles to the keyword 'options' ??? > -- > View this message in context:http://old.nabble.com/what-does-options-mean-----tp26146827s27240p261... > Sent from the jQuery General Discussion mailing list archive at Nabble.com. |
|
|
Re: what does options mean ???Thanx for the replies guys. I have a better understanding
|
| Free embeddable forum powered by Nabble | Forum Help |