JavaScript arguments, prototype, constructor, inheritance

Arguments

In every JavaScript function a private variable argument is automatically created, holding array of the arguments passed to the function.

Prototype

Every object has a special property, prototype. This property allows you to add properties/methods to all objects created from that object constructor. The prototype object loads before the object constructor does anything. Therefore by using prototype we can add properties, methods to both native objects and user-defined objects.

Constructor

Every instance of an object has a constructor property. It returns the Function object that created that instance of the object.

Inheritance

The prototype property is an object with no initial properties/methods. When we add properties/methods to this object, we automatically add them to all instances of the object. However, instead of adding properties/methods to the prototype object, we could replace the prototype object with an object that already has the properties/methods we want.

References

http://www.sitepoint.com/oriented-programming-2/

https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: