Skip to content

Instantly share code, notes, and snippets.

View GarrettS's full-sized avatar

Garrett Smith GarrettS

View GitHub Profile
@GarrettS
GarrettS / newApply.js
Created March 10, 2011 05:49
newApply
function F(){}
function newApply(ctor, args) {
var i,
fp = F.prototype = ctor.prototype; // Copy prototype.
if(fp) {
fp.constructor = ctor;
}
i = new F;
ctor.apply(i, args); // Apply the original constructor.
return i;
It didn't look like it need much time, or to achieve any depth. Just
copy the source text and work down it inserting comments on the things
that stand out. When the first line of code is a 'fix' for pre-ECMA 262
3rd edition browsers (a standard that came out in 1999 and where the
most recent browser that needed the 'fix' is IE 4, in a system that does
not support IE in any version) then you don't need depth to see fault.
- return !!(node && method in node && node[method].apply);
1079 + return !!(node && method in node &&
1080 + (typeof node[method] === 'function' ||
1081 + String(node[method]).indexOf('function') === 1)); // IE reports as object, prepends space