0

Is there any way in javascript to create class which will create functions, not objects, just like Function class

var realFunc = new Function();
typeof realFunc; // function

var myFunc = new MyFunction();
typeof myFunc; // object :(

I want to add some methods to function, but not to all of them. I don't want to add methods to each function object, better to add them to prototype of my class, isn't it?

redexp
  • 4,765
  • 7
  • 25
  • 37
  • Just have `myFunction` return a function, and call it as `var myFunc = myFunction()`. – Waleed Khan Oct 22 '13 at 17:57
  • Do you need methods from `function` that aren't present on `object`? If not, does it really matter which native object your class extends? – Evan Davis Oct 22 '13 at 17:58
  • What do you mean by "class"? No, all javascript function objects do inherit directly from `Function.prototype`, and there is no (standard-conformant) way to change this. – Bergi Oct 22 '13 at 18:01
  • 3
    You can't subclass Function, see http://stackoverflow.com/questions/19188458 – bfavaretto Oct 22 '13 at 18:03

0 Answers0