SyntaxError: "use strict" not allowed in function with non-simple parameters
ã¡ãã»ã¼ã¸
Firefox: SyntaxError: "use strict" not allowed in function with default parameter SyntaxError: "use strict" not allowed in function with rest parameter SyntaxError: "use strict" not allowed in function with destructuring parameter Chrome: SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
ã¨ã©ã¼ã®ç¨®é¡
SyntaxErrorã
ä½ããã¾ããããªãã£ãã®ãï¼
次ã®å¼æ°ã®ãã¡ãããããæã¤é¢æ°ã®å
é ã« "use strict" ãã£ã¬ã¯ãã£ããæ¸ããã¦ãã¾ã:
ECMAScript 仿§ã«åã£ã¦ããã®ãããªé¢æ°ã®å
é ã§ã¯ "use strict" ã使ç¨ã§ãã¾ããã
ä¾
>Function ã¹ãã¼ãã¡ã³ã
ãã®ã±ã¼ã¹ã§ã¯ã颿° sum ã¯æ¢å®å¤ãæã¤å¼æ° a=1 㨠b=2 ãæã£ã¦ãã¾ã:
function sum(a=1, b=2) {
// SyntaxError: "use strict" not allowed in function with default parameter
"use strict";
return a + b;
}
颿°ã strict ã¢ã¼ãã«ãããããã¤ã¹ã¯ãªããå
¨ä½ãã¾ãã¯ã¨ã³ã¯ãã¼ã¸ã£ã¼é¢æ°ã strict ã¢ã¼ãã«ãªã£ã¦ããããªãã"use strict" ãã£ã¬ã¯ãã£ãã颿°ã®å¤å´ã«ç§»åã§ãã¾ã:
"use strict";
function sum(a = 1, b = 2) {
return a + b;
}
Function å¼
function å¼ã§ã¯ãå¥ã®åé¿çãã¨ããã¨ãã§ãã¾ã:
var sum = function sum([a, b]) {
// SyntaxError: "use strict" not allowed in function with destructuring parameter
"use strict";
return a + b;
};
ããã¯ã次ã®å¼ã«å¤æã§ãã¾ã:
var sum = (function () {
"use strict";
return function sum([a, b]) {
return a + b;
};
})();
ã¢ãã¼é¢æ°
ã¢ãã¼é¢æ°ã this 夿°ã«ã¢ã¯ã»ã¹ããå¿
è¦ãããå ´åãã¢ãã¼é¢æ°ãã¨ã³ã¯ãã¼ã¸ã£ã¼é¢æ°ã¨ãã¦ä½¿ç¨ã§ãã¾ã:
var callback = (...args) => {
// SyntaxError: "use strict" not allowed in function with rest parameter
"use strict";
return this.run(args);
};
ããã¯ã次ã®å¼ã«å¤æã§ãã¾ã:
var callback = (() => {
"use strict";
return (...args) => {
return this.run(args);
};
})();