thank you for your information....I think Ihave to rewrite most of my object...thanks anyway
On Nov 9, 12:50 pm, kangax <[EMAIL PROTECTED]> wrote: > On Nov 8, 12:23 am, vtsuper <[EMAIL PROTECTED]> wrote: > > > here are the third style > > > var test = new Frm('frm1',{method:'post',url:'testing.php'}); > > > var test = new Frm('frm1','post','testing.php'); > > > var test = new Frm({id:'frm1',method:'post',url:'testing.php'}); > > > which style that the prototypejs developer suggest us to use?? > > It's all about doing what makes more sense in your particular > situation : ) > If your function needs more than 2-3 arguments, it's a good idea to > replace them with one object. Javascript's objects are unordered > collections, which makes them an ideal candidate for passing data in > *any* order: > > someFunction({ foo: 1, bar: 2 }); > // is identical in its effect to > someFunction({ bar: 2, foo: 1 }); > > while: > > someFunction(1, 2); > someFunction(2, 1); > > could easily differ. > > Some of prototype.js methods follow a pattern of having an optional > `options` parameter. This parameter is meant to be an object and is > usually the last one (as it makes it easy to omit it). `Ajax.Request` > is a good example. > > In your particular case, try only leaving required data as actual > arguments and put the rest into an optional object: > > var Frm = Class.create({ > options: { > method: 'post' > }, > initialize: function(element, url, options) { > this.element = $(element); > if (!this.element) throw Error('element is required'); > this.url = url; > id (!this.url) throw Error('url is required'); > this.options = Object.extend( > Object.clone(this.options), > options || { } > ); > // ... > } > > }); > > [...] > > -- > kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---