1

I have figure out this code

function getAllProperties(obj){
    var result={
        properties:[],
        methods:[]
    };
    var proto = obj;
    while(proto !== null){
        var props = Object.getOwnPropertyNames(proto);
        props.forEach(function(v){
            typeof proto[v] === "function" ? result.methods.push(v) : result.properties.push(v);
        });
        proto = Object.getPrototypeOf(proto);
    }
    return result;
}

And the parameter I passed in is canvas context object(obtain by canvas.getContext('2d')).The code words fine with Chrome . But it comes out that firefox get the 'Illegal operation on WrappedNative prototype object' Error . Can anyone tell me what's wrong with it?

1 Answer 1

0

When you write proto[v] you might actually invoke property accessor functions (for example if the property has been defined with a get/set as per HTML5) without an actual instance context. This causes the error.

Try getting Object.getOwnPropertyDescriptor to access the property without actually invoking it. The result might have a value property or a get/set property that are actually invoked when you access the field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.