javascript - Date.getTime() v.s. Date.now() -


i noticed now() can called date object. gettime() can called instance of date.

var dd1 = new date();  //console.log(dd1.now()); //throws error -> typeerror: object mon aug 19 2013 16:28:03 gmt-0400 (eastern daylight time) has no method 'now' console.log(dd1.gettime());  console.log(date.now()); //console.log(date.gettime()); //throws error ->typeerror: object function date() { [native code] } has no method 'gettime' 

is there formal name difference? difference between "static" , "non-static." when create new instance of date, shouldn't methods inherited?

it's difference between properties of constructor object , properties of constructor object's prototype. "now" property property of date constructor itself, , not property of date.prototype. it's opposite situation "gettime".

semantically makes sense: concept of "now" independent of particular date instance. "gettime" method intended report on timestamp date represented particular date instance.

if you're defining own constructors, can create "class methods" (i hesitate call them that, whatever) this:

function myconstructor() {   // ... }  myconstructor.somemethod = function() {   // ... } 

then myconstructor.somemethod() calls function independently of particular instance of class.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -