ujc
3/14/2016 - 9:21 PM

[Case study: Applying advanced javascript] Code 2

[Case study: Applying advanced javascript] Code 2

// In older IE, this function doesn't inherit from Function.prototype
// so there's no .apply() we can use.
// This will throw an error
document.getElementById.apply(document, ['myDiv']) // Error!


// The solution:
(Function.prototype.apply).apply(document.getElementById, [document, ['myDiv']]);  // Smooth!