What is the "prototype" linkage for Objects created via the Object Literal Notation in JavaScript? -
my first post on stack overflow , complete newbie here , still getting used rules / annotations followed on forum , please excuse aspiring "developer" ;-)
while reading through crockford's "good parts", came across line said:
every object linked prototype object can inherit properties. objects created object literals linked object.prototype, object comes standard javascript.
so test out wrote following jscript code:
var student = {} console.log(student.isprototypeof(object.prototype))
note:
- i executing via browser console , hence function -
console.log(...)
. - i guessing way student variable declared here using "object literal notation". isn't correct ?
so second line -
console.log(student.isprototypeof(object.prototype))
returned false instead of true. shouldn't display true instead of false ?
well doesn't contradict lines book mentioned above ?
so here snippet in action -
var student = {}; alert(student.isprototypeof(object.prototype));
i sure missing here sure!
the prototype of student
(and other objects created via object initialiser) object.prototype
.
i guessing way
student
variable declared here using "object literal notation". isn't correct ?
yes, that's 1 word it. spec calls object initialiser.*
so second line -
console.log(student.isprototypeof(object.prototype))
returned false instead of true. shouldn't display true instead of false ?
no, because student
isn't prototype of object.prototype
; it's other way around:
var student = {}; snippet.log(object.prototype.isprototypeof(student)); // true
<!-- script provides `snippet` object, see http://meta.stackexchange.com/a/242144/134069 --> <script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
side note: overwhelming convention in javascript use mixed case initial capital letter constructor functions , objects used pseudo-namespaces. simple objects, , simple functions, start lower case letter convention (so, student
rather student
).
* "initialiser" "s", not "z", reason. eich american, either whoever wrote spec british or, ecma european organization — until 1994 european computer manufacturers association, after all — perhaps editor insisted on british rather american english spelling.
Comments
Post a Comment