Is it possible to minify a DOM-reference with variable declaration?
For example document.documentElement:
var d = document;
console.log(d[d + 'Element']); // undefined
console.log(d[d] + 'Element'); // undefinedElement
Why does this not work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It doesn’t work because the string value of the
documentobject is not the string'document', it’s something like'[object HTMLDocument]'(may vary between browsers).When you concatentate the string
'Element'with thedocumentobject, the object is implicitly converted to a string, and you get a string like'[object HTMLDocument]Element', anddocument['[object HTMLDocument]Element']is undefined.