Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Maybe I can change Function.constructor function so every returned function will have your wrapper around it. Commented Aug 4, 2010 at 14:36
  • 2
    @yilmazhuseyin: no, you can't. Changing the Function constructor would only allow you to override functions created with new Function(str).
    – Andy E
    Commented Aug 4, 2010 at 14:49
  • yes you are right. function newConstructor(){alert("a");}; Function.prototype.constructor = newConstructor; did not work. Commented Aug 4, 2010 at 14:56
  • 1
    It's worth noting that someFunction in your example is the function you wish to intercept/extend. I had it backward when I first tried this but eventually figured out I was reading this wrong. Great example besides that.
    – Dan
    Commented Aug 14, 2014 at 22:42
  • I wanted to inject an function before another one and I needed to know about this and Function.prototype.call to pass the correct this to my hooked function. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
    – Motomotes
    Commented Mar 25, 2015 at 3:20