js模擬類

var body = {       //類app

    create: function(name, age){this

        this.name = name,prototype

        this.age = age對象

    },io

    sayName: function(){console

        console.log(this.name);function

    },方法

    sayAge: function(){apply

        console.log(this.age);co

    },

    country: 'china'

}

function NEW(Class, param){   //建立對象的方法

    function _new(){

        Class.create.apply(this, param);

    }

    _new.prototype = body;

    return new _new();

}

var obj = NEW(body, ['ly', 12]);

相關文章
相關標籤/搜索