美文网首页
js es6之前如何实现继承

js es6之前如何实现继承

作者: gis杭州 | 来源:发表于2018-11-14 21:27 被阅读0次
    function Person(){}
    Person.prototype.dance = function(){};
    
    function Ninja(){}
    Ninja.prototype = new Person();
    
    //因为上方设置原型,导致了constructor也被指向了Person,手动改回来
    Object.defineProperty(Ninja.prototype,"constructor",{
      enumerable:false,//不可遍历
      value:Ninja,
      writable:true
    }
    
    

    相关文章

      网友评论

          本文标题:js es6之前如何实现继承

          本文链接:https://www.haomeiwen.com/subject/jsesfqtx.html