模拟new的过程

        function NewObj () {
            var Constructor = [].shift.call(arguments);
            var obj = Object.create ? Object.create(null) || {}; //建立空对象,Object.create第一个参数传入null,建立无原型的对象app

            obj.__proto__ = Constructor.prototype; //设置原型指向prototype

            Constructor.apply(obj, arguments); //调用构造器,给对象设置自身属性对象

            return obj; //返回该对象
        }原型

相关文章
相关标签/搜索