object instance javascript code example

Example 1: object object javascript

person = {
    'name':'john smith'
    'age':41
};

console.log(person);
//this will return [object Object]
//use
console.log(JSON.stringify(person));
//instead

Example 2: javascript get all instances of a class

MyClass.allInstances = [];
MyClass.allInstances.push(this);
//However, you need some way to figure out when to remove instances from this array, or you'll leak memory.

Example 3: new instance of object javascript

function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

var car1 = new Car('Eagle', 'Talon TSi', 1993);

console.log(car1.make);
// expected output: "Eagle"

Tags:

Java Example