ecmascript-5

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

无人久伴 提交于 2019-12-09 05:33:05
问题 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

Async Function in Getter w/ Return in Callback

末鹿安然 提交于 2019-12-08 19:28:44
问题 I want to define a read-only object property that asynchronously fetches a value and then returns it using the new EcmaScript 5 getters. However, the property always returns undefined even though magicValue in the example code below is definitively never undefined. Also, when I just return 'xxx'; the printed value is still undefined . It only works when I return outside the callback function. It seems like return is being executed immediately regardless of whether the callback of

How does inheritance work in ES5-Javascript?

牧云@^-^@ 提交于 2019-12-08 08:37:26
问题 For the below code, var customer={ name: "Tom Smith", speak: function(){ return "My name is " + this['name']; }, address: { street: '123 Main St', city: "Pittsburgh", state: "PA" } }; Below is my visualisation of customer object, My question: Does customer object inherit properties(built-ins) of Object.prototype only? Are the properties(built-ins) of Object function type object are also for the purpose of inheritance? If yes, What is the syntax for customer object to inherit Object properties

How can I alert supported EcmaScript version of the browser?

别等时光非礼了梦想. 提交于 2019-12-08 08:16:52
问题 Is there a way to alert the supported EcmaScript version of the current environment where I run my JavaScript? 回答1: Short answer : No. Long answer : First of all, browsers doesn't implement ECMAScript but a language based on that specification (e.g. JavaScript for Firefox, JScript for Microsoft). Often, they can implement part of the standard, and complete the standard in a next version of the language (it happened in JavaScript 1.8 / 1.8.1 / 1.8.5 about ES5 for example, see New in JavaScript

Documenting complex JavaScript Objects with custom Inheritance System

…衆ロ難τιáo~ 提交于 2019-12-08 08:12:01
问题 I'm currently trying to migrate an existing server-side JavaScript API from its existing manually copy-and paste Inheritance System to a better and more reliable system. The pure prototyping cannot be used because state (variables) of the objects must also be inherited and must not be overriden in parent Objects. So i'm thinking about using a good solution from John Reisig described here: http://ejohn.org/blog/simple-javascript-inheritance/ which workrs great for my case. The only challenge i

LOOKAHEADs for the JavaScript/ECMAScript array literal production

左心房为你撑大大i 提交于 2019-12-08 04:11:23
问题 I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC and have problems with the ArrayLiteral production. ArrayLiteral : [ Elision_opt ] [ ElementList ] [ ElementList , Elision_opt ] ElementList : Elision_opt AssignmentExpression ElementList , Elision_opt AssignmentExpression Elision : , Elision , I have three questions, I'll ask them one by one. This is the second one. I have simplified this production to the following form: ArrayLiteral: "[" ("," | AssignmentExpression ","

Array.map and lifted functions in Javascript

孤街浪徒 提交于 2019-12-08 03:40:29
问题 How come var a = "foo / bar/ baz ".split('/'); a.map( function (e) { return String.prototype.trim.call(e) } ) works, while this doesn't... a.map( String.prototype.trim ); 回答1: Try this: a.map(Function.prototype.call.bind(String.prototype.trim )) The reason why this works and just mapping String.prototype.trim doesn't work is because, as others have pointed out, the this will be undefined when the function tries to trim the array element. What this solution does is, it creates a new function,

Assign new property to empty object which has frozen prototype

心已入冬 提交于 2019-12-08 03:33:08
问题 Why can't I assign new properties to non-frozen object, which has frozen prototype: Working without Object.freeze: 'use strict' //This object will be prototype of next objects var defaults = { name: 'def name', sections: { 1: { secName: 'def sec name' } } }; //So we have an empty object with prototype set to our default object. var specificObject = Object.create(defaults); specificObject.sections = {}; console.log(specificObject.hasOwnProperty('sections')); //true specificObject.sections['1']

Clarication needed for implementing properties with the revealing module pattern using Html5 getters and setters

流过昼夜 提交于 2019-12-07 15:45:59
问题 I've searched a lot for how to do properties in Javascript. Most all of the revealing module pattern I've seen has exclusively exposed functions, and from experience I know if I expose an object, I'm only really getting a copy of the value right there and then, thus simply I could have a function getMyThing() and setMyThing and expose that. However I'm wanting to expose real properties I've seen the oldschool defineGetter which I'm avoiding and the newer Object.defineProperty( which I had

Is there a way to get the decimal and thousands separator in ECMAscript Internationalization API?

痞子三分冷 提交于 2019-12-07 06:04:47
问题 I'm trying to use the new Javascript internationalization API, and would like to know if there is a way to get the decimal and thousands (grouping) separator for a Intl.NumberFormat instance? There is a resolvedOptions method on the object, but that does not provide the symbols. In case anybody's wondering, then for en-US, these would be a comma , and period . , such as in 1,000.00 . 回答1: I'm afraid ECMA-402 standard does not define the API that let you access separators. There is also