I am trying to list the properties / functions for Date in JavaScript using the below code:
var mydate=new Date();
for(var i in mydate){
console.log(i);
}
Properties of date objects (or rather those that they inherit) are non-enumerable. Using Object.getOwnPropertyNames does reaveal them, so you can try this instead:
for (var o=new Date(); o!=null; o=Object.getPrototypeOf(o)) {
console.log("on ["+o+"] itself:");
Object.getOwnPropertyNames(o).forEach(function(p) {
console.log(p)
});
}
Alternatively, for checking the properties of native objects, you might just fire up their Docs - either in the spec or at MDN. Also, simply console.log
ging them usually produces an expandable view on an object that also includes the prototypes and their properties.
Many built-in objects have their methods set to not be enumerable, and therefore won't show up in a for..in
loop.
You should instead look up some documentation, and then you can test if your browser supports certain things like:
if( 'now' in Date)