Properties of an object are looked up from two places:- the object itself (Obj.foo), and
- if the property does not exist, on the prototype of the object (Obj.prototype.foo).
New objects are created using a constructor, which is a regular function invoked usingnew
Thenew
constructor call (e.g.new Foo()
):- creates a new object,
- sets the prototype of that object to Foo.prototype and
- passes that as
this
to the constructor.
沒有留言:
張貼留言