ecmascript-5

What is `base value` of `reference` in ECMAScript(ECMA-262 5.1)?

…衆ロ難τιáo~ 提交于 2019-12-03 07:25:59
I've been trying to understand how this value is set in javascript, and found ECMAScript Language Specification pretty much helpful. I was reading section 8.7 reference specification type and found that reference in ECMAScript is made of 3 component, base value , referenced name , strict reference flag to understand section 11.2.3 . I can assume what are referenced name and strict reference flag from their name, but i don't understand what is the base value . The document says that base value is either undefined , String , Boolean , Number and Object , but it does not say how it is set and

Why do built-in functions not have a prototype property?

有些话、适合烂在心里 提交于 2019-12-03 07:24:08
Given that the ES 5.1 standard states that... 1) Note at the foot of http://es5.github.com/#x13.2 NOTE A prototype property is automatically created for every function, to allow for the possibility that the function will be used as a constructor. 2) http://es5.github.com/#x15.3.5.2 NOTE Function objects created using Function.prototype.bind do not have a prototype property. (which implies that all other functions do) ...why do built-in functions no longer have a prototype property?: [].push.prototype; //undefined Math.max.prototype; //undefined Moreover these built-ins cannot be used as

How to provide ECMAScript 5 (ES 5)-shim?

夙愿已清 提交于 2019-12-03 06:30:32
问题 ECMAScript Fifth Edition (released December 2009) introduces a bunch of new methods (see this table for details). However, there still are older browsers out there which do not implement those new methods. Luckily, there exists a convenient script (written in JavaScript) - ES5-shim - which implements those methods manually in environments where they don't exist. However, I am not sure how to provide ES5-shim... Should I just "give" it to all browsers, like so: <script src="es5-shim.js"><

Shim vs. Sham: What is the difference?

大城市里の小女人 提交于 2019-12-03 05:28:32
问题 What is the difference between a shim an a sham? Is it enough to include es5-shim.min.js and es6-shim.min.js or should I also include es5-sham.min.js and es6-sham.min.js? 回答1: According to this Github page the shims include all monkey-patches that faithfully represent the ES5 features. In other words: you can use the features provided by these files as if you were using ES5 proper. The shams, however contain those features that can not be emulated with other code. They basically provide the

Avoiding .call() and .apply() using .bind()

我的未来我决定 提交于 2019-12-03 05:18:36
I'm looking for a way to accomplish a certain task and that is, going from jQuery.when.apply( null, promiseArray ).done(...) to when( promiseArray ).done(...) As you might know, .bind() can get used to create something like default arguments and also doing some quite nifty stuff. For instance, instead of always calling var toStr = Object.prototype.toString; // ... toStr.call([]) // [object Array] we can do it like var toStr = Function.prototype.call.bind( Object.prototype.toString ); toStr([]) // [object Array] This is fairly cool (even if there is a performance penality invoking .bind() like

Why do we need the isPrototypeOf at all?

↘锁芯ラ 提交于 2019-12-03 05:06:56
问题 this page states: Note: isPrototypeOf differs from instanceof operator. In the expression object instanceof AFunction, the object prototype chain is checked against AFunction.prototype, not against AFunction itself Ok I don't really get what they are trying to tell us. Isn't object instanceof AFunction exactly the same as `AFunction.prototype.isPrototypeOf(object)? or am I wrong? Why do we need the isPrototypeOf at all? If i ever need to do p.isPrototypeOf(o) couldn't I just do o instanceof p

Javascript Reduce an empty array

半城伤御伤魂 提交于 2019-12-03 04:50:39
问题 When I reduce the array, I am trying to get the number zero, but I dont clearly understand the behaviour of the function [].reduce(function(previousValue, currentValue){ return Number(previousValue) + Number(currentValue); }); result TypeError: Reduce of empty array with no initial value seems that if the array is empty I can't reduce it [""].reduce(function(previousValue, currentValue){ return Number(previousValue) + Number(currentValue); }); result "" If the only element in the array is an

type=“text/ecmascript” vs type=“text/javascript”

核能气质少年 提交于 2019-12-03 04:50:08
问题 I was reading a book about learning JavaScript, and there was these paragraphs: ...in middle of 1997, Microsoft and Netscape, with associate of European Computer Manufactures Association, released the first version of a standard that named ECMAScript or with official form ECMA-262 ... As much as I was found in this book and something like this, JavaScript and ECMAScript are the same and are different just in name. From other hand, in Dreamweaver, bracket, and some other editors, there's some

Accessors are only available when targeting ECMAScript 5 and higher

断了今生、忘了曾经 提交于 2019-12-03 04:16:31
I am trying to run this code but it is giving me following errors: Animal.ts(10,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. Animal.ts(14,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. interface IAnimal{ name : string; sayName():string; } class AnimalImpm implements IAnimal{ private _name : string = '[Animal]'; get name():string{ return this._name; } set name(name:string){ this._name = name; } constructor(name:string){ this.name = name; } sayName():string { console.log(`My name is ${this.name}`); return "Hello"

Call ES5 class method from static method

别来无恙 提交于 2019-12-03 03:52:21
I want to call an inner function from a static function that was called without an instance, like so: Foo.Bar = function (options) { Autodesk.Viewing.Extension.call(this, options); ... this.innerFunc = function innerFunc(){ ... } }; Foo.Bar.prototype.constructor = Foo.Bar; Foo.Bar.SomeStaticFunc = function () { innerFunc(); } Use: Foo.Bar.SomeStaticFunc(); . But I get SomeStaticFunc is not a function . The example here uses a variable for the class, like var Foo.Bar = function (options) {... but isn't that the same as making an instance of the class like so and calling an inner function? let x