OOP: Javascript

create object
function person() {  // person object
  ... 
  }
use object
var someone = new person();
(AUTO-GENERATED:)
var jd = new person('John','Doe');

jd.age;  // undefined
jd.fname;  // John
jd.getfullname();  // John Doe
add method
function person(fname,lname) {

  this.getfullname = function() {
    return this.fname + ' ' + this.lname;
  }

}
alert( jd.getfullname() );
add property to instance
person.height='72in';  // 'jd' doesn't inherit 'height'
add inheritable property
person.prototype.height='72in';  // 'jd' inherits 'height'
discover prototype of object
jd.constructor;

See Rob

See Jim

See English