File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments