开发者

Extended properties in JS?

Can we associate property with object at runtime in javascript Just like we do in C#. like

class abc
{
a =1;
b=2;
}

abc obj;

obj.a // is right
//but can we do 
obj.c //....开发者_StackOverflow中文版...... by any mean


function abc(){
    this.a = 1;
    this.b = 2;
}
var obj = new abc();
var obj2 = new abc();
obj.c = "something"; // will affect only this instance
obj2.prototype.d = "something else"; // this will influence all abc instances
alert(obj.d);


Yes you can do that in JS. That new property 'c' however will only be valid for that particular instance of teh class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜