IE8 getPrototypeOf method

后端 未结 3 768
-上瘾入骨i
-上瘾入骨i 2020-12-16 05:04

Pretty simple:

I have code using Object.getPrototypeOf(...) to get the inherited classes of a Dojo Widget (just a JS object). Object.getPrototypeO

相关标签:
3条回答
  • 2020-12-16 05:11

    Use https://github.com/kriskowal/es5-shim. Among other things, it supports Object.getPrototypeOf.

    Source: ECMAScript 5 polyfills from Modernizr project

    0 讨论(0)
  • 2020-12-16 05:15

    Classes created with Dojo.declared store metadata with their superclasses so you don't need to use getPrototypeOf.

    I think you can get the first superclass with

    MyClass.prototype.constructor._meta.bases[1]
    

    and its prototype with

    MyClass.prototype.constructor._meta.bases[1].prototype
    

    (bases[0] seems to be the class itself)


    Although why are you even needing to get the prototype? Its very likely you will end up reimplementing some feature that is already provided by dojo.declare

    0 讨论(0)
  • 2020-12-16 05:30

    Jon Resig's polyfill works http://ejohn.org/blog/objectgetprototypeof/

    I have made it even smaller

    if (typeof Object.getPrototypeOf !== "function")
        Object.getPrototypeOf = "".__proto__ === String.prototype
            ? function (object) {
                return object.__proto__;
            }
            : function (object) {
                // May break if the constructor has been tampered with
                return object.constructor.prototype;
            };
    
    0 讨论(0)
提交回复
热议问题