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
-~----------~----~----~----~------~----~------~--~---

Reply via email to