prototype Property

The functions in JavaScript are objects and they contain methods and properties. Inbuilt methods of object are like apply() and call() and some of the properties are length and constructor. There is another property of the function objects called prototype.

In the below example from the function foo() you can access its properties similar to another object.

function foo(a, b) {
    return a * b;
}
foo.length
foo.constructor
Function()

As soon as you define the function a property prototype gets created. Its initial value is an empty object.

typeof foo.prototype

"object"

It is similar to property created like below.

foo.prototype = {}

You can augment(add) properties and methods with empty object. They'll be used when you use foo() as a constructor.

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents