How to access properties from the prototype chain that are shadowed by own properties?

后端 未结 1 740
忘掉有多难
忘掉有多难 2021-01-19 11:15

Let\'s create an object which inherits from another anonymous object:

var obj = Object.create({
    func: function () { alert(\'Inherited method\'); }
});


        
相关标签:
1条回答
  • 2021-01-19 11:54
    Object.getPrototypeOf(obj).func();
    

    will make sure the inherited function gets executed.

    In older browsers (the above is ES5), you can use

    obj.__proto__.func();
    

    but this is deprecated.

    http://jsfiddle.net/pimvdb/PLxHB/5/

    0 讨论(0)
提交回复
热议问题