Results 1 to 2 of 2

Thread: prototype bind

  1. #1
    Join Date
    Apr 2011

    prototype bind

    Function.prototype.bind = function() {
        var __method = this;
        var args = Array.prototype.slice.call(arguments);
        var object=args.shift();
        return function() {
            return __method.apply(object,
    i just dont know what use of args.concat(Array.prototype.slice.call(arguments)) , i assume that is arguments which pass to apply .

    but when i use this, i got confuse .
         function func() {
    	    var args=Array.prototype.slice.call(arguments);
    		var object = args.shift();
    	 func(1,2,3);     //  2,3,1,2,3

  2. #2
    Join Date
    Jun 2008
    I think you're confusing yourself, here.

    Function.prototype.bind, in your example, returns a new function. That function applies a "this" value (first arg of .bind()) to your old function. It passes the extra (arg 2, 3, etc) arguments that were sent to .bind(), at the time it was bound, plus (args.concat) the arguments that the user invoked it with.

    If you invoke .bind() with only one argument, then you will see no extra arguments in your function.

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