Reason behind using 'instanceof function() {}'?

Viewed 1383

On Mozilla Developer Center, there is a page about the Function.prototype.bind function and provides a compatibility function for browsers which do not support this function.

However, when analyzing this compatibility code I cannot find out why they use instanceof nop. nop has been set to function() {}. What part of the ECMA specification on bind does this correspond with? And what variables are an instance of function() {}?

The following returns false, so I don't completely know what it is used for. What things return true when doing an instanceof function() {} check?

(function() {}) instanceof (function() {}) // false

The code is as follows:

Function.prototype.bind = function( obj ) {
    if(typeof this !== 'function')
      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');

    var slice = [].slice,
        args = slice.call(arguments, 1), 
        self = this, 
        nop = function () {}, 
        bound = function () {
          return self.apply( this instanceof nop ? this : ( obj || {} ), 
                              args.concat( slice.call(arguments) ) );    
        };

    bound.prototype = this.prototype;

    return bound;
};
2 Answers
Related