oop - how to define a custom method on the javascript object class -


i going on javascript parts , came across example, author trying explain how able call superclass:

object.method('superior', function (name) {     var = this,         method = that[name];     return function (  ) {         return method.apply(that, arguments);     }; }); 

an example of using code:

super_get_name = that.superior('get_name'); 

however chrome wouldn't recognize method on object. tried doing same thing using defineproperty didn't work either.. help?

update: method cause known conflicts jquery? put following @ first js file in page:

i error in line 2062 in jquery-1.11.0.js:

uncaught typeerror: object function (name) {     var = this,         method = that[name];     return function (  ) {         return method.apply(that, arguments);     }; } has no method 'exec'  

this effected code:

    // filters     ( type in expr.filter ) {         if ( (match = matchexpr[ type ].exec( sofar )) && (!prefilters[ type ] ||             (match = prefilters[ type ]( match ))) ) {             matched = match.shift();             tokens.push({                 value: matched,                 type: type,                 matches: match             });             sofar = sofar.slice( matched.length );         }     } 

any idea what's going on?

the author of book explains piece of code work need define method function first:

throughout book, method method used define new methods. definition:

function.prototype.method = function (name, func) {  this.prototype[name] = func;  return this; }; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -