Here is an updated answer
var newFunc = oldFunc.bind({}); //clones the function with '{}' acting as it's new 'this' parameter
However .bind
is a modern ( >=iE9 ) feature of JavaScript (with a compatibility workaround from MDN)
It does not clone the function object additional attached properties, including the prototype property. Credit to @jchook
The new function this variable is stuck with the argument given on bind(), even on new function apply() calls. Credit to @Kevin
function oldFunc() {
console.log(this.msg);
}
var newFunc = oldFunc.bind({ msg: "You shall not pass!" }); // this object is binded
newFunc.apply({ msg: "hello world" }); //logs "You shall not pass!" instead
(new newFunc()) instanceof oldFunc; //gives true
(new oldFunc()) instanceof newFunc; //gives true as well
newFunc == oldFunc; //gives false however