Object Literal - Node.js Object

Node.js examples for Object:Object Operation

Description

Object Literal

Demo Code


console.log("*** Object Literal ***");

var fred1 = { firstName: "Fred", lastName: "Flintstone", kind: "Person", name: function() { return this.firstName + " " + this.lastName; } };
var barney1 = { firstName: "Barney", lastName: "Rubble", kind: "Person", name() { return this.firstName + " " + this.lastName; } };

console.log(fred1);/*from  w  ww.j  av  a2  s  .  c  om*/
console.log(fred1.name());
console.log(barney1);
console.log(barney1.name());

// New Stuff
console.log(Object.getPrototypeOf(fred1));                                              // Object{...}
console.log(fred1.__proto__);                                                           // Object{...}
console.log(Object.getPrototypeOf(barney1));                                            // Object{...}
console.log(barney1.__proto__);                                                         // Object{...}
// console.log(fred1.prototype);                                                        // Doesn't exist, prototype is only a property of functions
// console.log(fred1.[[Prototype]]);                                                    // And [[Prototype]] is internal and exposed via __proto__ and Object.getPrototypeOf() for objects

Related Tutorials