Skip to content

Commit 5b81f9a

Browse files
committed
added prototype pattern
1 parent b7f69b6 commit 5b81f9a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pattern/prototype-pattern.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// build our blueprint object
2+
var MyBluePrint = function MyBluePrintObject() {
3+
4+
this.someFunction = function someFunction() {
5+
console.log( 'some function' );
6+
};
7+
8+
this.someOtherFunction = function someOtherFunction() {
9+
console.log( 'some other function' );
10+
};
11+
12+
this.showMyName = function showMyName() {
13+
console.log( this.name );
14+
};
15+
16+
};
17+
18+
function MyObject() {
19+
this.name = 'testing';
20+
this.age = 20;
21+
}
22+
MyObject.prototype = new MyBluePrint();
23+
24+
//another may to add prototype method
25+
MyObject.prototype.showAge = function(){
26+
console.log(this.age);
27+
}
28+
29+
// example usage
30+
var testObject = new MyObject();
31+
testObject.someFunction(); // logs "some function"
32+
testObject.someOtherFunction(); // logs "some other function"
33+
testObject.showMyName(); // logs "testing"
34+
testObject.showAge(); // logs "20"

0 commit comments

Comments
 (0)