I'd actually looked at Snook's article, but hadn't managed to find an answer from it. Either I didn't get it, or my problem doesn't actually involve an issue with passing values by reference/value - I'm not sure which.
On Jan 17, 5:02 pm, Tobie Langel <[EMAIL PROTECTED]> wrote: > Snook has a pretty good > explanation:http://snook.ca/archives/javascript/javascript_pass/ > > Best, > > Tobie > > On Jan 17, 5:54 pm, iporter <[EMAIL PROTECTED]> wrote: > > > Ok, I've figured out that I can use this.options={} within the > > initialize function to declare defaults, and then follow this with > > 'Object.extend(this.options, options || {});' to customise these > > defaults > > > But I still don't understand why I get different behaviour in the > > above example for this.options.value and this.value - can you tell me > > why? > > > Thanks > > > On Jan 17, 4:30 pm, iporter <[EMAIL PROTECTED]> wrote:> In the below code, > > I expect two alerts '1 : 1' and then '1 : 1', but > > > in reality I get '1 : 1' and '2 : 1'. For some reason, the > > > declaration of the second object of class myClass alters the first > > > object of the same class. However, it only alters > > > 'this.options.value', and not 'this.value'. Can you tell me why this > > > behaviour occurs, and how to resolve it? > > > > Cheers > > > > --------------------------------------------------------------------------- > > > var myClass = Class.create({ > > > options:{}, > > > value: false, > > > initialize: function(options) { > > > this.options.value = options.value; > > > this.value = options.value; > > > }, > > > myAlert:function() { > > > alert(this.options.value + ' : ' + this.value); > > > } > > > > }); > > > > var classObj1 = new myClass({value:1}); > > > classObj1.myAlert(); > > > var classObj2 = new myClass({value:2}); > > > classObj1.myAlert(); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
