I have a class and I want from inside the class to save as a class variable the name of the object using the class:
var xxx = new MyClass(); // on the constructor this.name should be init to "xxx"
Ive already tried this approach:
But I can’t get it work from the class constructor itself.
xxxis just a variable holding a reference to theObjectin memory. If you want to give that object a property of name, you should pass it as an argument.You could keep a hash of your objects to avoid creating different variables each time:
Here is a fiddle: http://jsfiddle.net/x9uCe/