Jump to content

General Javascript ES6 'strict' Question.


Pryme8
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

 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  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.


let-me-introduce-you-to-the-internet-mem

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...