www.webdeveloper.com
Results 1 to 2 of 2

Thread: help with this code

  1. #1
    Join Date
    Apr 2011
    Posts
    7

    help with this code

    Code:
      function addMethod(object, name, fn) {
               var old = object[name];
               object[name] = function(){
    		if (fn.length == arguments.length)
    			return fn.apply(this, arguments)
    		else if (typeof old == 'function')
    			 return old.apply(this, arguments);
    					     };
    
    }
    var ninja = {};
    addMethod(ninja,'whatever',function(){ var no='no args';return no; });
    addMethod(ninja,'whatever',function(a){var one='one args'; return one; });
    addMethod(ninja,'whatever',function(a,b){var two='two args'; return two; });
    alert(ninja.whatever());
    alert(ninja.whatever(1,2));
    i dont konw why i call the ninja.whatever function with args ,it response with the corresponding function ? how ?

  2. #2
    Join Date
    Jun 2008
    Posts
    106
    I don't understand what you want, here. Can you try to explain it more clearly?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles