ecmascript-5

Disable “use the function form of use strict” but keep the “Missing 'use strict' statement” warning

戏子无情 提交于 2019-12-23 07:15:38
问题 I am using jslint to validate my code. I have "use strict" on all my pages. How can I disable the message "use the function form of 'use strict'" but keep the "Missing 'use strict' statement" warning, so I won't forget to put it on new files? Thanks 回答1: According to Crockford's post, you'll want to wrap everything in a function... (function () { "use strict"; // the rest of your file goes here... }()); You could also use jshint instead, which has a "globalstrict" option that can do exactly

How can I tell when this.setState exists in ES6?

*爱你&永不变心* 提交于 2019-12-23 02:17:13
问题 I have been struggling with trying to migrate my React code from ES5 to ES6. As I have found out by now, this is no longer automatically bound which causes all sorts of hell. I am trying to figure out by trial and error what objects are being passed around. So far I can find everything and adjust accordingly. However when it comes to this.setState I am having problems because it is not visible in console.log !!!! See screenshot in ES5: and here is the same kind of code in ES6: Please teach me

How can I tell when this.setState exists in ES6?

梦想的初衷 提交于 2019-12-23 02:17:11
问题 I have been struggling with trying to migrate my React code from ES5 to ES6. As I have found out by now, this is no longer automatically bound which causes all sorts of hell. I am trying to figure out by trial and error what objects are being passed around. So far I can find everything and adjust accordingly. However when it comes to this.setState I am having problems because it is not visible in console.log !!!! See screenshot in ES5: and here is the same kind of code in ES6: Please teach me

What is Prologue Directives?

醉酒当歌 提交于 2019-12-22 07:09:08
问题 I stumbled upon something people choose to call Prologue Directives. More commonly known with the "use strict"; string literal in JavaScript. Which i already know all about. But the common denominator Prologue Directive. What it is? There's very little documentation available on this subject. Best one is the question i linked. ECMAScript multiple Prologue Directives My questions are generic: What are they? What can they be used for? Who uses them and why? Can i make them? Should i? 回答1: No

What is the enumerable argument for in Object.create?

泄露秘密 提交于 2019-12-22 05:17:27
问题 In what usages of Object.create do you want to set enumerable to true ? 回答1: A property of an object should be enumerable if you want to be able to have access to it when you iterate through all the objects properties. Example: var obj = {prop1: 'val1', prop2:'val2'}; for (var prop in obj){ console.log(prop, obj[prop]); } In this type of instantiation, enumerable is always true, this will give you an output of: prop1 val1 prop2 val2 If you would have used Object.create() like so: obj = Object

How to detect ECMAscript version?

六月ゝ 毕业季﹏ 提交于 2019-12-22 03:24:37
问题 I want to see what ECMAscript version I'm using in my browser(e.g,chrome 59) ,because there is some difference between ECMAscript3 and ECMAscript5 when dealing with something RegExp stuff. I've found the relevant information about this,but I can't find a specific answer about how to detect the ECMAscript version. Thank's in advanced. 回答1: May be you can try to use some data structures that are specifically added in ES6 like Map , Set etc. This is to differentiate between ES5 and ES6 but you

Why are anonymous function expressions and named function expressions initialized so differently?

老子叫甜甜 提交于 2019-12-21 17:20:04
问题 I'm looking at section 13 or the ECMAScript specification (v. 5). An anonymous function expression is initialized as follows: Return the result of creating a new Function object as specified in 13.2 with parameters specified by FormalParameterListopt and body specified by FunctionBody. Pass in the LexicalEnvironment of the running execution context as the Scope. Pass in true as the Strict flag if the FunctionExpression is contained in strict code or if its FunctionBody is strict code. this

What is an ECMAScript “native object”?

本小妞迷上赌 提交于 2019-12-21 05:21:18
问题 According to the ECMA-262 a native object object in an ECMAScript implementation whose semantics are fully defined by this specification rather than by the host environment A built-in object is defined as object supplied by an ECMAScript implementation, independent of the host environment, that is present at the start of the execution of an ECMAScript program. with a note Standard built-in objects are defined in this specification, and an ECMAScript implementation may specify and define

Why does TypeScript pack a class in an IIFE?

若如初见. 提交于 2019-12-21 03:39:59
问题 Here is a TypeScript class: class Greeter { public static what(): string { return "Greater"; } public subject: string; constructor(subject: string) { this.subject = subject; } public greet(): string { return "Hello, " + this.subject; } } It is transpiled to IIFE when TS targets ES5: var Greeter = /** @class */ (function () { function Greeter(subject) { this.subject = subject; } Greeter.what = function () { return "Greater"; }; Greeter.prototype.greet = function () { return "Hello, " + this

Future of the with-statement in Javascript

自闭症网瘾萝莉.ら 提交于 2019-12-21 01:16:14
问题 I know that usage of the with -statement is not recommended in Javascript and is forbidden in ECMAScript 5, but it allows one to create some nice DSLs in Javascript. For example CoffeeKup-templating engine and the Zappa web DSL. Those uses some very weird scoping methods with the with -statement to achieve DSLish feeling to them. Is there any future with the with -statement and these kinds of DSLs? Can this DSL-effect be achieved without the with -statement? 回答1: with being "forbidden" in