I was thinking to minimize some javascript code but I get this "illegal invocation" error when I try to call a function through an alias
var d = document.createElement;
d('input');
Does anybody know why? tx
Looks like this has been addressed by others. It boils down to the fact that
document.createElement
checks to make sure that this
refers to document
. You can bypass this behavior by doing the following:
Either A: always use it as document.createElement(tagname)
OR
B
var o = document.createElement
o.call(document, tagname)
C
var d = document.createElement.bind(document);
(from above answer)
See http://blog.vjeux.com/2011/javascript/hook-document-createelement.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With