Pryme8 Posted August 1, 2018 Share Posted August 1, 2018 So I have not been able to find an answer to a behavior I have come across... I know this is not really a forum for this question but I figured someone here might know whats good. So I have come across a really odd (at least I think it is) behavior when deleting variables references inside a new Object. "SyntaxError: Delete of an unqualified identifier in strict mode." Maybe I'm just dense and am deleting the var unnecessarily but here is the setup: So lets say we have an index page where we include/link a few JS files. File1.js -> class TEXTURE0_EMISSIVE extends ASSET{ constructor (parent) { super(parent) } compile(){ ...some script var somevar = 10 delete somevar ...some script } } Assuming there is already an Asset Object defined. and then on the main page Index -> document.ready....{ someParentObject(){ var texture = new TEXTURE0_EMISSIVE(this); texture.compile(); } } Basically a set up like this makes the page fail to compile the js file that has the delete referenced in it. Ive never had this problem until I shifted to es6 structure. I might just be dumb though and it could be simple (im prolly just not supposed to delete the var)..... I did not get much sleep the past couple days and my minds not working like it normally does. *UPDATE* I think I figured it out... Im pretty sure GoDaddy is injecting "use strict" at some point on the document scope? I say this because I can not reproduce on my local sever. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted August 1, 2018 Share Posted August 1, 2018 we are in es8 already. var is now function scoped. i guess that's the mistake. But generally yes, you are the programmer, the strickt mode is meant for you to recognize usually java script errors, is nan is undef. javascript gives a damn. so put it in a strick mode. http://exploringjs.com/es6/ch_variables.html Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 1, 2018 Author Share Posted August 1, 2018 wtf we are in es8 are you for real? I must of had my head under a rock. https://www.ecma-international.org/ecma-262/8.0/index.html Jeeeez... lots of reading to do. Nabroski 1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted August 1, 2018 Share Posted August 1, 2018 I recently went thru all my source for my QI extension. Changed every reference of var to let or const unless it was absolutely needed, 1 place. Changed to "for of" in every place where "for(let i = 0.." was just indexing. tons of places (Typescript has an option for transpiling ' --downlevelIteration ' for ES3 & ES5). Changed to backquote for all strings concatenated with a "+". Kind of a mechanical process, but helped by using an ide with good search. Cleaning made the code more readable. Does not replace reading, but for libraries it seemed worth it. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 1, 2018 Author Share Posted August 1, 2018 Sounds like I am going through the transition you just described! Thanks for the input. Quote Link to comment Share on other sites More sharing options...
samme Posted August 1, 2018 Share Posted August 1, 2018 You can't delete a variable, only object properties. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted August 1, 2018 Share Posted August 1, 2018 remember rainy days back in 2 0 1 6 doing stuff like const a = Array.from(somestuff).map( entries => ( { print: entries } ) ); console.log( a.print ) and now every day seems like sunshine: Object.entries( ...[somestuff] ) or even [].concat(...somestuff.entries() ); they done pretty neat stuff with es8 or i just spend to much time on the babel side of the internet. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 1, 2018 Author Share Posted August 1, 2018 32 minutes ago, samme said: You can't delete a variable, only object properties. I am so dumb.... My god I knew this and have no clue what I was thinking... I think its time to go take a nap. DylanD 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.