Kithraya
Kithraya

Reputation: 398

Effective difference between Function.prototype.call.bind, returning a called function, and function assignment with .call

As far as I can see, the following three approaches accomplish the exact same thing: determining if Element.prototype has native property tagName, irrespective of Element.prototype.hasOwnProperty being locally overwritten:


  var ownsBind = Function.prototype.call.bind( Object.prototype.hasOwnProperty );

  var ownsReturnCallOfOriginal = function ownsReturnCallOfOriginal( obj, prop ) { 
      return Object.prototype.hasOwnProperty.call(obj, prop);
  }

  var ownsAssigned = Object.prototype.hasOwnProperty;

  var EP = Element.prototype;

  console.log( ownsBind( EP, 'tagName' ) ); // true
  console.log( ownsReturnCallOfOriginal( EP, 'tagName' ) ); // true
  console.log( ownsAssigned.call( EP, 'tagName' ) ); // true

In particular, what is the effective difference between ownsBind and ownsReturnCallOfOriginal, and what are some of the reasons for choosing one approach over the other two?

Upvotes: 0

Views: 41

Answers (0)

Related Questions