Search

1/17/2009

Beginning Object-Oriented JavaScript - SlideShare

Beginning Object-Oriented JavaScript - SlideShare

Constructor functions
when invoked with new, functions return an object known as this
you can modify this before it’s returned

Built-in constructors
Object Array Function Regexp Number String Boolean Date Error, Syntax Error ,...

Prototype…
is a property of the function objects
>>> var boo = function(){};
>>> typeof boo.prototype
"object"

The prototype is used when a function is called as a constructor

__proto__
The objects have a secret link to the prototype of the constructor that created them
__proto__ is not directly exposed in all browsers

Inheritance

function NormalObject() {
this.name = 'normal';
this.getName = function() {
return this.name;
};
}
function PreciousObject(){
this.shiny = true;
this.round = true;
}
PreciousObject.prototype =
new NormalObject();

Beget object

function object(o) {
function F(){}
F.prototype = o;
return new F();
}

沒有留言: