开发者

Prototypal Inheritance. Whats wrong with this simple example?

    function a (){
        this.testing = 'testing';
    }

    function b (){

    }

    b.prototype = new a();



    co开发者_StackOverflow中文版nsole.log(b.testing);

The console shows undefined, rather than 'testing'. What am I doing wrong?


You haven't made an instance of 'b' yet.

var bInstance = new b();
console.log(bInstance.testing);

In other words, the properties of the prototype only appear on objects of type b, not on the b() constructor function itself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜