javascript - Constructor functions in js -


trying understand outputs below - why checks false when directly used on objects - true when checked on instances ?? can 1 explain - missing here?

    function book2(){     this.title =  "high performance javascript";     this.publisher = "yahoo! press"; };  book2.prototype.author = "hgghghg";  var b = new book2();  alert(book2.hasownproperty("title"));  //false alert(book2.hasownproperty("tostring"));  //false alert("title" in book2); //false alert("tostring" in book2); //true   alert(b.hasownproperty("title"));  //true alert(b.hasownproperty("tostring"));  //false alert("title" in b); //true  alert("tostring" in b); //true 

book2 not have title attribute, sets title attribute on new object. book2 inherit tostring method prototype.

hasownproperty, name suggests, tells whether particular object has given property. not @ prototype.
in tells whether object has property anywhere, including prototype chain.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -