ecmascript-5

`this` in global scope in ECMAScript 6

烂漫一生 提交于 2019-12-05 12:16:57
I've tried looking in the ES6 draft myself, but I'm not sure where to look: Can someone tell me if this in ES6 necessarily refers to the global object? Also, will this object have same members as the global scope? If you could answer for ES5 that would be helpful as well. I know this in global scope refers to the global object in the browser and in most other ES environments, like Node. I just want to know if that's the defined behavior by the spec or if that's extended behavior that implementers have added (and if this behavior will continue in ES6 implementations). In addition, is the global

ES6 as the typescript target compiler option for angularjs or angular2

為{幸葍}努か 提交于 2019-12-05 11:58:34
The compiler option for my angularjs application is as below. Should I use any other package to transpile es6 to es5 again if I change the target to es6 ? { "compilerOptions": { "target": "es5", // Change this to es6 "module": "commonjs", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "outDir": "./wwwroot/app/" }, "exclude": [ "node_modules", "wwwroot" ] } Targeting ES5 is currently a baseline requirement *According to The ES6 Compatibility Table : class isn't supported in Chrome (latest) Android (latest) Note:

What is Prologue Directives?

丶灬走出姿态 提交于 2019-12-05 09:31:14
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? No need for documentation. Just look in the source . A Directive Prologue is the longest sequence of

Does a function expression have its own scope/lexical environment

强颜欢笑 提交于 2019-12-05 09:03:31
I'm reading the Execution Context / Lexical Environment section of the ECMA 262 5 specification . It states the following: (emphasis added) A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic structure of ECMAScript code such as a FunctionDeclaration , a WithStatement,

Is there anyway to have instances share the same function yet at the same time have private variables?

偶尔善良 提交于 2019-12-05 08:15:59
I have this piece of code: var Human=function(name){ this._name=name; }; Human.prototype.Shout=function(){ alert(this._name); }; var tom=new Human("tom"); var john=new Human("john"); alert(tom.Shout===john.Shout); Right now ._name is not "private". I want to make ._name "private", but at the same time i do not wish to create additional functions for each instance of Human (in other words tom.Shout Must be === to john.Shout) because creating additional functions for each instance is just well.. unnecessary (ok offtopic - we can debate this on another thread) My conclusion is that what I'm

Factory function in a Typescript declares file, with and without the new keyword

让人想犯罪 __ 提交于 2019-12-05 04:35:57
The following code will create a factory function in ES5: function MyClass(val) { if (!(this instanceof MyClass)) { return new MyClass(val); } this.val = val; } This function can be called with or without the new keyword: var a = new MyClass(5); var b = MyClass(5); This works fine in Typescript, however I can't figure out how to create a declares file with merging that describes both behaviors. Is there a way to do this? interface MyClass { val: {}; } interface MyClassConstructor { (val: {}): MyClass; new (val: {}): MyClass; } declare const MyClass: MyClassConstructor; 来源: https:/

Javascript get and set availability in browsers

冷暖自知 提交于 2019-12-05 03:33:46
Which browsers do not support the get and set methods for object prototypes? I believe this is a feature of ES5, an I know it works in Chrome, but I am wondering if it is safe to use for ajax apps. Here's an example: var foo = function () {}; foo.prototype = { get name () { return this._name; }, set name (n) { this._name = n || "bar"; } }; Here's a compatibility table for you. http://kangax.github.com/es5-compat-table/ See the Getter in property initializer and Setter in property initializer rows. According to the table: Firefox 4 Safari 5 Chrome 7-11 Other browsers (including IE9) are not

How do JavaScript versions correlate to ECMAScript versions?

拥有回忆 提交于 2019-12-05 03:23:15
For example, [].map was "implemented in JavaScript 1.6." Is that an ES5 method? How does the 1.6 correlate to an ECMAScript version? There aren't really strict correspondences between the version numbers Mozilla uses and the ECMAScript standard's version numbers. There's a table on Wikipedia that might be what you're looking for -- you'll see that JavaScript 1.6 corresponds to ECMAScript 3 and then some additional extensions. [].map specifically was standardized in ECMAScript 5, but to my understanding, the feature was first introduced by Firefox before the ECMAScript 5 standard was even

Create custom elements v1 in ES5, not ES6

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 03:20:52
问题 Right now, if you follow the exact specifications of v1 of the custom elements spec, it's not possible to use custom elements in browsers that don't support classes. Is there a way to create v1 custom elements without using the class syntax so that they are fully functional in Chrome, FireFox and IE11. Also, since IE11 doesn't have native support for custom elements, I'm assuming we will probably need to use some pollyfills, so what polyfills or libraries do we need in order to make this work

Is there a library which implements new Javascript/Ecmascript 5 methods for older versions?

对着背影说爱祢 提交于 2019-12-05 02:22:10
Although Ecmascript 5 introduces some completely new features, it also adds some new methods (bind, trim, map, etc.) which should be perfectly possible to implement (albeit slower) in current versions. Does a library exist which implements these backwards compatible features (and no more, excluding Prototype et. al.) Kris Kowal and friends have built the es5-shim. It was part of Narwhal, but now lives on its own: http://github.com/kriskowal/es5-shim/ Was: I've taken to using the global-es5.js shim from narwhal: http://github.com/280north/narwhal/blob/master/engines/default/lib/global-es5.js