1

I saw this question in stackoverflow and seriously did not understand on how does Function.prototype.bind.apply work?

Use of .apply() with 'new' operator. Is this possible?

function Shan(name){
   this.name = name;
}

var s = new (Function.prototype.bind.call(Shan, "shankar"));

The above code returns me an instance of Shan constructor.

Community
  • 1
  • 1
ShankarGuru
  • 627
  • 1
  • 6
  • 17
  • http://blog.slaks.net/2015-06-18/code-snippets-and-in-the-darkness-bind-them/ – SLaks Feb 25 '16 at 22:27
  • What exactly is the question? Is your code working and you want to know why it works? Or is your code not working and you want to know why it doesn't work? In general, you don't use `.apply()` with constructors, but rather create a factory function that can do the work for you. – jfriend00 Feb 25 '16 at 22:33
  • @jfriend00: Wanted to understand on how Function.prototype.bind.call works? – ShankarGuru Feb 25 '16 at 22:34
  • Does the code you posted work? – jfriend00 Feb 25 '16 at 22:34
  • Are you asking about call or apply? Your question contradicts your code – Nick Zuber Feb 25 '16 at 23:17

0 Answers0