strict-mode

How to get function name in strict mode [proper way]

落花浮王杯 提交于 2019-12-01 06:58:50
问题 arguments.callee unfortunatelly deprecated, and using it throws an error in "strict mode". Is there any new proper(standard) alternative for getting function name inside actual function? Or will it be in future plans ECMA6, 7? Recent answer is no more than dirty hack and not acceptable for me answer. And arguments.callee.caller.name not working either (nodejs v7.5.0) 回答1: Is there any new proper (standard) alternative for getting function name inside actual function? No, there is not. Or will

Is there any way to check if strict mode is enforced?

元气小坏坏 提交于 2019-11-29 19:56:26
Is there anyway to check if strict mode 'use strict' is enforced , and we want to execute different code for strict mode and other code for non-strict mode. Looking for function like isStrictMode();//boolean The fact that this inside a function called in the global context will not point to the global object can be used to detect strict mode: var isStrict = (function() { return !this; })(); Demo: > echo '"use strict"; var isStrict = (function() { return !this; })(); console.log(isStrict);' | node true > echo 'var isStrict = (function() { return !this; })(); console.log(isStrict);' | node false

Is there any way to check if strict mode is enforced?

≯℡__Kan透↙ 提交于 2019-11-28 16:16:41
问题 Is there anyway to check if strict mode 'use strict' is enforced , and we want to execute different code for strict mode and other code for non-strict mode. Looking for function like isStrictMode();//boolean 回答1: The fact that this inside a function called in the global context will not point to the global object can be used to detect strict mode: var isStrict = (function() { return !this; })(); Demo: > echo '"use strict"; var isStrict = (function() { return !this; })(); console.log(isStrict)

How to get caller from strict mode?

99封情书 提交于 2019-11-28 09:41:35
Strict and non-strict code can be mixed. But you can't use caller even if the call to it is not in strict code. Does anybody know any workaround? I tried this: (function strict(){ "use strict"; nonStrict();//ok nonStrictCaller();//error :( })(); function nonStrict(){ return 011;//Octal literals are not allowed in strict mode } function nonStrictCaller(){ return nonStrictCaller.caller; } Here's an evil hack that only works in V8. The 140 bytes version: function x(a,b,c){function d(e,f){d=f}c=(b=Error)[a='prepareStackTrace'];b.captureStackTrace(b[a]=d,x);d.stack;b[a]=c;return d} And the less

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

一笑奈何 提交于 2019-11-28 08:10:29
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 Global object as it is created via variable declaration and so has DontDelete attribute ": >>> foo 2 >>>

what is “strict mode” and how is it used?

孤街浪徒 提交于 2019-11-28 02:52:02
I've been looking over the JavaScript reference on the Mozilla Developer Network, and I came across something called "strict mode" . I read it over and I'm having trouble understanding what it does. Can someone briefly explain (in general) what its purpose is and how it is useful? Its main purpose is to do more checking. Just add "use strict"; at the top of your code, before anything else. For example, blah = 33; is valid JavaScript. It means you create a completely global variable blah . But in strict mode its an error because you did not use the keyword "var" to declare the variable. Most of

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

家住魔仙堡 提交于 2019-11-28 01:50:47
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? 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.write(x); Octal literals are not allowed because disallowing them discourages programmers from using leading

Why is body.scrollTop deprecated?

二次信任 提交于 2019-11-27 14:17:02
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 parents moves upward. [Obviously, body refers to document.body ] It's Chrome's own incorrect behavior that

Can I disable ECMAscript strict mode for specific functions?

牧云@^-^@ 提交于 2019-11-27 06:56:52
I don't find anything about my question here on MDC or the ECMAscript specifications. Probably somebody knows a more 'hacky' way to solve this. I'm calling "use strict" on every javascript file in my environment. All my files start like this (function(win, doc, undef) { "use strict"; // code & functions }(window, window.document)); Now, I have a custom function which handles errors. That functions uses the .caller property to provide a context stack trace . Looks like this: var chain = (function() { var _parent = _error, _ret = ''; while( _parent.caller ) { _ret += ' -> ' + _parent.caller.name

what is “strict mode” and how is it used?

三世轮回 提交于 2019-11-27 04:59:56
问题 I've been looking over the JavaScript reference on the Mozilla Developer Network, and I came across something called "strict mode" . I read it over and I'm having trouble understanding what it does. Can someone briefly explain (in general) what its purpose is and how it is useful? 回答1: Its main purpose is to do more checking. Just add "use strict"; at the top of your code, before anything else. For example, blah = 33; is valid JavaScript. It means you create a completely global variable blah