javascript - Why does this syntax cause it's property constructor to longer point to it's own constructor? -
i learning prototypes in javascript, , came across behavior, guess matter of fact, wondered if there practical reason it...
let's create object:
function stormtrooper(){} and want fill properties , methods, because after they're stormtroopers , they'll same :) (and better reason, don't want every instance created having it's own individual properties , methods, waste of memory , cause duplication).
stormtrooper.prototype = { name : null, type: null, id : null, rank : null, 'years of service' : null, weapon : null, utilitybelt : null, givereport : function(){ alert('"click.." '+ this.type +' ' + this.id + ', clear... nothing report..."click"'); } }; when console.dir(stormtrooper.prototype); , crack open __proto__: property , look it's constructor property, point object, in end native object. why?
i know can explicitly add constructor property when create it, wondered why is? (that points object instead of stormtrooper).
thanks in advance!
any object created object literal:
var obj = { hello: "world" }; will plain object constructed object constructor. that's you've got in code:
stormtrooper.prototype = { // ... };
Comments
Post a Comment