-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.js
32 lines (23 loc) · 980 Bytes
/
prototype.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// prototype property
function printStuff(myDocuments)
{
this.documents = myDocuments;
}
// We add the print () method to PrintStuff prototype property so that other instances (objects) can inherit it:
printStuff.prototype.print = function()
{
console.log(this.documents);
}
/*Create a new object with the PrintStuff () constructor, thus allowing this new object
to inherit PrintStuff's properties and methods. */
var newObj = new printStuff("I am a new object");
/* newObj inherited all the properties and methods, including the print method, from the PrintStuff function.
Now newObj can call print directly, even though we never created a print () method on it. */
newObj.print() //I am a new object
//prototype attribute
function Account()
{
}
var userAccount = new Account();
/* userAccount initialized with the Account() constructor
and as such its prototype attribute (or prototype object) is Account.prototype.*/