File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 1010 Description: adding convenient funcationality to a language
1111*/
1212
13+ if ( typeof Function . prototype . method !== "function" ) {
14+ Function . prototype . method = function ( name , implementation ) {
15+ this . prototype [ name ] = implementation ;
16+ return this ;
17+ } ;
18+ }
19+
1320var Person = function ( name ) {
1421 this . name = name ;
1522} .
2229 } ) ;
2330
2431var a = new Person ( 'Adam' ) ;
25- a . getName ( ) ; // 'Adam'
26- a . setName ( 'Eve' ) . getName ( ) ; // 'Eve'
27-
28- if ( typeof Function . prototype . method !== "function" ) {
29- Function . prototype . method = function ( name , implementation ) {
30- this . prototype [ name ] = implementation ;
31- return this ;
32- } ;
33- }
32+ console . log ( a . getName ( ) ) ; // 'Adam'
33+ console . log ( a . setName ( 'Eve' ) . getName ( ) ) ; // 'Eve'
3434</ script >
3535</ body >
3636</ html >
You can’t perform that action at this time.
0 commit comments