ecmascript-5

Why does EcmaScript 5 strict mode go to such great lengths to restrict the identifier `eval`

此生再无相见时 提交于 2019-12-20 00:23:01
问题 According to the spec (Annex C), strict-mode code can't do pretty much anything that might assign any identifier with the name eval . I can understand that one might want to restrict use of the actual eval function, but I don't see what purpose is served by restricting use of the name? 回答1: I can only speculate, but it seems to me that ES5-strict is saying that eval and arguments should be considered as raw syntax, not identifiers. It is reasonable that these two features should be

JavaScript date function returns “Date {Invalid Date}” in Firefox browser

偶尔善良 提交于 2019-12-19 20:36:13
问题 Facing a problem with JavaScript Date function, returns "Date {Invalid Date}" in Firefox browser but works fine in Google chrome. // My Input is new Date("Sat Jan 01 00:00:00 EST 1"); // Works fine in google chrome // Result: Mon Jan 01 2001 10:30:00 GMT+0530 (India Standard Time) // Not working in Firefox (Version: 15.0.1) // Result: Date {Invalid Date} 回答1: Date does not take a timezone parameter in that way. My thought is that Chrome is just ignoring it. new Date(year, month, day [, hour,

why do we use `Boy.prototype = new Human;` to simulate inheritance?

孤者浪人 提交于 2019-12-19 09:23:27
问题 i don't get why everyone is using Boy.prototype = new Human; to simulate inheritance. Look, what we want is the function's of A right? we can do that without instantiating a new A (in fact instantiating a new A does give us undesirable results, in the sense that we are actually running the instantiating function which isn't what we want) So isn't this a better solution? for (var prop_name in Human.prototype) { Object.defineProperty( Boy.prototype, prop_name, Object.getOwnPropertyDescriptor

Is there any reason to use Object.create() or new in JavaScript?

ぃ、小莉子 提交于 2019-12-19 05:56:52
问题 I've been using the new keyword in JavaScript so far. I have been reading about Object.create and I wonder if I should use it instead. What I don't quite get is that I often need to run construction code, so I don't see how Object.create is going to work at all since it does not trigger any functions to run. Could anyone tell me, In which case should I use Object.create instead of new ? 回答1: So far, if you want to create an object, you can only use literals: var obj = {}; or the Object

Angular equivalent of jQuery $.map?

本小妞迷上赌 提交于 2019-12-18 18:37:11
问题 I'm transitioning from relying on jQuery to building apps in AngularJS. It's recommended in a number of places to not mix jQuery and Angular code. One thing I miss though is the jQuery $.map function for arrays. I know this could be re-written using the native Javascript map function, but this is not implemented in all browsers (notably, IE < v9). So, is there an Angular equivalent, or should I got back to writing for (var x = 0; x < foo; x += 1) {...} so I can stop including jQuery? UPDATE

ECMAScript 5 Date.parse results for ISO 8601 test cases

旧街凉风 提交于 2019-12-18 17:32:17
问题 What result is right for the following test cases? //Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 console.log(Date.parse("2012-11-31T23:59:59.000Z"));//1354406399000 NaN NaN 1354406399000 NaN console.log(Date.parse("2012-12-31T23:59:59.000Z"));//1356998399000 1356998399000 1356998399000 1356998399000 1356998399000 console.log(Date.parse("2012-12-31T23:59:60.000Z"));//NaN NaN NaN NaN 1356998400000 console.log(Date.parse("2012-04-04T05:02:02.170Z"));//1333515722170 1333515722170

JavaScript Closures - Using the ECMA Spec, please explain how the closure is created and maintained

Deadly 提交于 2019-12-18 11:43:00
问题 I'm reading about JavaScript closures. I'm familiar with Execution Contexts, how the Lexical Environment is maintained, and very familiar with Lexical Scoping. I want to know how closures in JavaScript are created and maintained . Sometimes it's hard for me to grasp such important concepts without knowing how it is actually doing it. I know that, according to Wikipedia, a closure is is a function or reference to a function together with a referencing environment—a table storing a reference to

Getting Error Promise is undefined in IE11

淺唱寂寞╮ 提交于 2019-12-18 11:42:27
问题 I am converting React code to typescript, target in tsconfig is es5. on running in IE 11 i get an error "Promise is undefined" I know i need to polyfill,but how? I am not using Babel. Following is my Webpack.config var webpack = require("webpack"); var Promise = require('es6-promise').Promise; var paths = require('./config/paths'); var HtmlWebpackPlugin = require('html-webpack-plugin'); //var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); var AureliaWebpackPlugin =

EcmaScript 5 browser implementation

扶醉桌前 提交于 2019-12-18 10:39:28
问题 So Safari and Chrome have started in their betas to implement some ES5 stuff. For instance Object.create is in them. Do any of you know if there is a website that shows the progress made in the browsers? ATM i need to use Object.freeze, and wanted to see which browsers (if any) supported that yet. 回答1: Here's an up to date list for major engines: http://kangax.github.com/es5-compat-table/ 来源: https://stackoverflow.com/questions/2280115/ecmascript-5-browser-implementation

(Open Source) Examples of JavaScript Prototypical OO

♀尐吖头ヾ 提交于 2019-12-18 10:02:38
问题 Bounty Edit: I'm looking for code written in a pure prototypical OO paradigm (think Self). Not a mixture of prototypical OO and classical OO. I don't want to see generic OO wrappers but simply usage of prototypical OO techniques and only prototypical OO techniques. Reference Related Question: Prototypical OO in JavaScript In the above question I mainly focused on Can write prototypical OO like this? Do we need constructors and initialization logic, What are the alternatives? New question: