码迷,mamicode.com
首页 > 其他好文 > 详细

动态原型模式

时间:2018-07-06 20:20:41      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:eof   对象   就是   OLE   span   color   模式   fun   his   

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);
                }
            }
        }
    }

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

动态原型模式

标签:eof   对象   就是   OLE   span   color   模式   fun   his   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!