Javascript 新建而不是Object.create

Javascript 新建而不是Object.create,javascript,object,Javascript,Object,通常我是这样做的: $.fn.MYPL = function (options) { return this.each(function () { myplg = Object.create(MYPL); myplg.init(options, this); }); }; IE6、IE7和IE8中不支持创建对象。我刚刚意识到,我可以替换对象 但是我不知道。。如何更改我的插件定义 我试过: var myplg = new MYPL(); 但它不起作用。感谢您

通常我是这样做的:

$.fn.MYPL = function (options) {
   return this.each(function () {
      myplg = Object.create(MYPL);
      myplg.init(options, this);
   });
};
IE6、IE7和IE8中不支持创建对象。我刚刚意识到,我可以替换对象

但是我不知道。。如何更改我的插件定义

我试过:

var myplg = new MYPL();
但它不起作用。感谢您的帮助。

对象。创建(MYPL)
设置对象原型。对于基于构造函数的方法,您可以尝试以下代码:

function MYPLConstructor() {}

for (var key in MYPL) {
     MYPLConstructor.prototype[key] = MYPL[key];
}

var myplg = new MYPLConstructor();
Object.create(MYPL)
设置对象原型。对于基于构造函数的方法,您可以尝试以下代码:

function MYPLConstructor() {}

for (var key in MYPL) {
     MYPLConstructor.prototype[key] = MYPL[key];
}

var myplg = new MYPLConstructor();
您可以在IE7和IE8中使用它。

您可以在IE7和IE8中使用它。

我看到不支持任何属性对象,因此,我编写了一个稍微更完整的实现,它至少可以让您设置值,并在有可用控制台时警告其他人,还可以抛出正确类型的错误消息

if (!Object.create) {
    Object.create = (function () {
        function _Object() {}

        return function(proto, props) {
            var o, k, d;
            if (proto !== null && typeof proto !== 'object')
                throw new TypeError('Object prototype may only be an Object or null');
            _Object.prototype = proto;
            o = new _Object();
            for (k in props) {
                if (typeof props[k] !== 'object')
                    throw new TypeError('Property description must be an object: ' + props[k]);
                for (d in props[k])
                    if (d === 'value')
                        o[k] = props[k].value;
                    else
                        if (console && console.warn)
                            console.warn('Object.create implementation does not support: ' + d);
            }
            return o;
        };
    }());
}
我看到了不支持任何属性对象,所以我编写了一个稍微更完整的实现,它至少可以让您设置值并警告其他人(如果有可用的控制台),还可以抛出正确类型的错误消息

if (!Object.create) {
    Object.create = (function () {
        function _Object() {}

        return function(proto, props) {
            var o, k, d;
            if (proto !== null && typeof proto !== 'object')
                throw new TypeError('Object prototype may only be an Object or null');
            _Object.prototype = proto;
            o = new _Object();
            for (k in props) {
                if (typeof props[k] !== 'object')
                    throw new TypeError('Property description must be an object: ' + props[k]);
                for (d in props[k])
                    if (d === 'value')
                        o[k] = props[k].value;
                    else
                        if (console && console.warn)
                            console.warn('Object.create implementation does not support: ' + d);
            }
            return o;
        };
    }());
}

MYPL
在何处以及如何定义?在何处以及如何定义
MYPL