I thought it would be as simple as:
if(typeof(Array.push) == 'undefined'){
And it works fine in Firefox, but not in IE, Chrome, Safari, Opera , they return all the properties / methods of their own Array object as 'undefined' using this test.
The .hasOwnProperty (prop) method only works with instances ... so it doesnβt work, but with trial and error, I noticed that it works.
//this works in Firefox/IE(6,7,8)/Chrome/Safari/Opera if(typeof(Array().push) == 'undefined'){ //not defined, prototype a version of the push method }
Is there anything wrong with using this syntax to determine if a property / method exists in a Native Object / ~ "JavaScript Class" ~, or is there a better way to do this?
javascript methods properties native typeof
scunliffe Feb 27 '09 at 17:33 2009-02-27 17:33
source share