strict-mode

Why is delete not allowed in Javascript5 strict mode?

两盒软妹~` 提交于 2019-11-27 04:10:21
I'm fairly new to javascript, but I'm in love with it's dangerously fast and loose expressiveness. That said, I noticed that apparently when operating in "use strict" mode, you can't delete objects. I'm not a huge fan of deleting things (since, in theory, scope should take care of that anyway), but I wonder what was the motivation behind removing this feature? The delete statement is still allowed in strict mode, but some particular uses of it are erroneous. It's only allowed for object properties, not simple names, and only for object properties that can be deleted. Thus var a = {x: 0};

Possible to enable “strict mode” in FireBug and Chrome's console?

☆樱花仙子☆ 提交于 2019-11-27 02:06:55
问题 With this page: <!DOCTYPE html> <html> <head> <script> "use strict"; var foo = 2; delete foo; </script> </head> <body></body> </html> Firebug console gives: applying the 'delete' operator to an unqualified name is deprecated >>> foo ReferenceError: foo is not defined foo But then this is successful: >>> var bar = 2; undefined >>> delete bar; true Even if you comment out delete foo; so that the script does not break, deleting bar is still successful despite the fact it "is a property of a

Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)

感情迁移 提交于 2019-11-26 17:23:14
问题 Why are Octal numeric literals not allowed in JavaScript strict mode? What is the harm? "use strict"; var x = 010; //Uncaught SyntaxError: Octal literals are not allowed in strict mode. <h1>Check browser console for errors</h1> In case a developer needs to use Octals (which can mistakenly change a numbers meaning), is there a workaround? 回答1: The "why" part of the question is not really answerable. As for "how", off the top of my head... "use strict"; var x = parseInt('010', 8); document

Why is body.scrollTop deprecated?

纵然是瞬间 提交于 2019-11-26 16:31:29
问题 It seems body.scrollTop (and body.scrollLeft ) are deprecated in ES5 strict-mode. What is the reason for this, given that it still seems okay to use these properties on other DOMElement s? Background Info: I have a function that tries to increase (or decrease, as specified) the scrollTop values of all the ancestors of an element , till one of these actually changes. I am wondering if, to stay complaint with strict-mode, I should specifically check against the body element as the chain of

Why is delete not allowed in Javascript5 strict mode?

懵懂的女人 提交于 2019-11-26 12:43:12
问题 I\'m fairly new to javascript, but I\'m in love with it\'s dangerously fast and loose expressiveness. That said, I noticed that apparently when operating in \"use strict\" mode, you can\'t delete objects. I\'m not a huge fan of deleting things (since, in theory, scope should take care of that anyway), but I wonder what was the motivation behind removing this feature? 回答1: The delete statement is still allowed in strict mode, but some particular uses of it are erroneous. It's only allowed for

Getting a reference to the global object in an unknown environment in strict mode

不羁岁月 提交于 2019-11-26 09:03:01
问题 What is the recommended way to get a handle to the global object in ES5 strict mode in an unknown host environment ? ECMAScript doesn\'t provide a built-in way to reference the global object that I\'m aware of. If it does, this is the answer I\'m looking for. In a known environment , the global object usually has a self-referential property. Since the global object is the VO for the global scope, properties of the global object are global variables, so we can use them get a handle to the