首页 > 其他 > 详细

动态原型模式

时间:2018-07-06 20:05:00      阅读:153      评论:0      收藏:0      [点我收藏+]
function Person1(name,age){
        this.name = name;
        this.age = age;
        if (typeof this.sayName != ‘function‘)
        {
            Person1.prototype.sayName = function(){
                console.log(this.name);
            }
        }
    }
function Person1(name,age){
        this.name = name;
        this.age = age;
        if (typeof this.sayName != ‘function‘)
        {
            Person1.prototype = {
                sayName:function(){
                    console.log(this.name);
                }
            }
        }
    }

上边和下边不一样,下边会断开以前的原型的指针,因为{}就是一个对象

动态原型模式

原文:https://www.cnblogs.com/jokes/p/9275289.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!