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

相关文章
相关标签/搜索