ecmascript-5

Where is the immutable binding record of the identifier in a named function expression stored in JavaScript?

两盒软妹~` 提交于 2019-11-28 08:18:36
问题 Recently I ran into some interesting facts about named function expressions (NFE). I understand that the function name of an NFE can be accessed within the function body, which makes recursion more convenient and saves us arguments.callee . And the function name is not available outside the function body. For example, var foo = function bar() { console.log(typeof bar); }; typeof foo; // 'function' typeof bar; // 'undefined', inaccessible outside the NFE foo(); // 'function', accessible inside

Why doesn't an octal literal as a string cast to a number?

冷暖自知 提交于 2019-11-28 06:51:05
In JavaScript, why does an octal number string cast as a decimal number? I can cast a hex literal string using Number() or + , why not an octal? For instance: 1000 === +"1000" // -> true 0xFF === +"0xFF" // -> true 0100 === +"0100" // -> false - +"0100" gives 100, not 64 I know I can parse with parseInt("0100" [, 8]) , but I'd like to know why casting doesn't work like it does with hex and dec numbers. Also, does anyone know why octal literals are dropped from ECMAScript 5th Edition in strict mode? CMS I'm a bit late to the question but I think I can give a good answer. The accepted answer

WeakMap implementation in EcmaScript5?

梦想的初衷 提交于 2019-11-28 06:24:39
I've run across a JavaScript library that implement a cross-browser WeakMap in ES5 . (WeakMap is slated for ES6 .) How can this possibly work without support in the JavaScript language itself? Edit: Just to be clear, I'm referring to a Weak Map, not a regular Map. I tested this project out using Chrome's profiler and the keys are not held by strong references. They get GC'ed without having to remove them from the WeakMap. It took me a while to grok the code, but then it hit me: the key itself is used to store a reference to the value. For example, several layers into set it does defProp(obj,

What really is a declarative environment record and how does it differ from an activation object?

岁酱吖の 提交于 2019-11-28 05:33:09
Okay, so I lately have been reading about ES-5 lexical environment scope and I am not sure if I really understand what is going on with how variables are stored in EcmaScript. I did some research but it didn't clarified my information, only brought me up to two questions. So there they are: The first one is about ES-3 activations objects / variable objects . After reading ES-3 Specification and some sources on the Internet I can assume that they are just normal object, for example like those created by new Object , but none of the sources says "yes, this is just a plain object" directly.

Function.prototype.bind

天涯浪子 提交于 2019-11-28 05:24:24
I've got pretty interesting question about EcmaScript-5 Function.prototype.bind implementation. Usually when you use bind, you do it this way: var myFunction = function() { alert(this); }.bind(123); // will alert 123 myFunction(); Okay so that's cool, but what is suppose to happen when we do this? // rebind binded function myFunction = myFunction.bind('foobar'); // will alert... 123! myFunction(); I understand that it's completely logical behavior in terms of how Function.prototype.bind is implemented ( https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind ). But

Why does `Object.prototype.toString` always return `[object *]`?

[亡魂溺海] 提交于 2019-11-28 05:23:05
问题 If you call Object.prototype.toString.call(anything) the result is always [object Something] , where Something could be one of several things. My question is why is the "object" part there? It seems superfluous to always have it there. It doesn't tell you anything about the argument which was passed in. Object.prototype.toString.call(null); => [object Null] Object.prototype.toString.call(undefined); => [object Undefined] Since null and undefined aren't objects (and fails CheckObjectCoercible

argument.callee.name alternative in the new ECMA5 Javascript Standard [duplicate]

六眼飞鱼酱① 提交于 2019-11-28 04:10:12
问题 This question already has answers here : Alternative to arguments.callee (2 answers) Closed 5 years ago . I'm working on porting some old code to 'strict mode', what are the alternatives to the argument.callee and similar argument.caller etc in the ECMA5 standard? ADDED INFO: I did not specify why I need the argument.caller/callee. The code I'm porting is using assert.ok(elemNode, arguments.callee.name + ": Entity - " + entityId + " has been found"); If it were simple recursion I could use

Difference between freeze and seal

被刻印的时光 ゝ 提交于 2019-11-28 02:43:25
I just heard about the JavaScript methods freeze and seal , which can be used to make any Object immutable. Here's a short example how to use it: var o1 = {}, o2 = {}; Object.freeze(o2); o1["a"] = "worked"; o2["a"] = "worked"; alert(o1["a"]); //prints "worked" alert(o2["a"]); //prints "undefined" What is the difference between freeze and seal ? Can they increase performance? Niccolò Campolungo Object.seal It prevents adding and/or removing properties from the sealed object; using delete will return false It makes every existing property non-configurable : they cannot be converted from 'data

Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)

家住魔仙堡 提交于 2019-11-28 01:50:47
Why are Octal numeric literals not allowed in JavaScript strict mode ? What is the harm? "use strict"; var x = 010; //Uncaught SyntaxError: Octal literals are not allowed in strict mode. <h1>Check browser console for errors</h1> In case a developer needs to use Octals (which can mistakenly change a numbers meaning ), is there a workaround? The "why" part of the question is not really answerable. As for "how", off the top of my head... "use strict"; var x = parseInt('010', 8); document.write(x); Octal literals are not allowed because disallowing them discourages programmers from using leading

Warning: Each child in an array or iterator should have a unique “key” prop

我与影子孤独终老i 提交于 2019-11-28 01:42:43
G'Day. I want to iterate over a bunch of JSON objects and turn them into React Elements. The objects look like this "fields": [ { key: "testname", "name": "testname", "altName": "", "visible": true, "groupVisibility": "public", "type": "text", "component": "input", "label": "Test Smart Input", "placeholder": "Some default Value", "required": "required", "validated": false, "data": [] }, { key: "password", "name": "password", "altName": "", "visible": true, "groupVisibility": "public", "type": "password", "component": "input", "label": "Test Smart Input", "placeholder": "Password", "required":