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?
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.getOwnPropertyDescriptorto 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.