ecmascript-5

What modernizer scripts exist for the new ECMAScript 5 functions?

旧时模样 提交于 2019-11-27 01:08:45
问题 ECMAScript 5 has quite a few nice additions. John Resig has a good overview here. Here is a good ECMAScript 5 compatibility table. A lot of this stuff can be "faked" for browsers that don't support these functions yet. Do you know of any scripts that can do this? I'm particularly interested in Object.create. For example, Douglas Crockford's JSON script checks if JSON functions exist before creating them. If there was more like the JSON one we could include them when we need to use the new

Function.prototype.bind

╄→гoц情女王★ 提交于 2019-11-27 00:59:47
问题 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

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

霸气de小男生 提交于 2019-11-26 23:35:05
问题 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":

Function Declarations Within Blocks according to the Google JavaScript style guide

旧街凉风 提交于 2019-11-26 23:18:44
问题 According to the Google JavaScript style guide, function declarations should not be declared within blocks since this is not a part of ECMAScript. However, I'm not entirely clear on what counts as a block. Specifically, I have a constructor function and I want to define a function within the scope of that constructor. Would this count as a function within a block, since it is within a set of {}? If so, does that mean every function declaration must be global? Some code for good measure: WRONG

javascript “use strict” and Nick's find global function

♀尐吖头ヾ 提交于 2019-11-26 23:09:57
问题 So I saw a function that was, quite frankly beautiful in its simplicity as it allowed you to find the global object ( which depending on environ at the time may NOT have been window ) while within an anonymous function; however when you throw javascripts' "use strict"; mode it crumbles, due to the evaluation of the keyword 'this' changing. There were a few ways to accomplish this? (function () { var win = function () { return (function () { return this; }()); }; //win now points to the global

Object.defineProperty in ES5?

末鹿安然 提交于 2019-11-26 23:01:39
I'm seeing posts about a 'new' Object.create that makes enumeration configurable. However, it relies on a Object.defineProperty method. I can't find a cross browser implementation for this method. Are we stuck writing for the old Object.create? I can't write things that won't work in IE6/7. There are several things that you can't emulate from the ECMAScript 5 Object.create method on an ECMAScript 3 environment. As you saw, the properties argument will give you problems since in E3-based implementations there is no way to change the property attributes. The Object.defineProperty method as

Why and how does ([![]]+[][[]])[+!+[]+[+[]]] evaluate to the letter “i”? [duplicate]

折月煮酒 提交于 2019-11-26 22:06:37
This question already has an answer here: Why does ++[[]][+[]]+[+[]] return the string “10”? 9 answers (![]+[])[+[]]… Explain why this works 1 answer While reading this article posted on dzone I found a snippet of JavaScript originally posted on Twitter by Marcus Lagergren . The following code apparently prints the string "fail" (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]; This involves implicit type casting and I'm trying to understand how exactly this line is interpreted. I've isolated each character (![]+[])[+[]] prints "f" (![]+[])[+!+[]] prints "a" ([![]]

Regex only capturing last instance of capture group in match

≡放荡痞女 提交于 2019-11-26 21:52:40
问题 I have the following regular expression in two different languages that produces the same odd results (javaScript and Flash). What I want to know is not how to fix it, but why the behavior is occurring? The Regular Expression: \[(\\{2}|\\\]|[^\]])*\] The goal here is to match a bracketed string, and ensure that I don't stop at an escaped bracket. If I have the text input [abcdefg] it is correctly matched, but the only thing returned as part of the capture group is g , where as I expect

How to inject custom service to angular component in plain ES5 (Javascript)?

不打扰是莪最后的温柔 提交于 2019-11-26 21:52:32
问题 I have a working angular2 Componen t. I implemented a class for some service (using ng.core.Class if that matters). What are the minimal steps to inject my service to my Component ? Should I include my service in bootstrap function? Should I use any of ng.core.Inject or ng.core.Injectable? All my experiments failed so far. 回答1: You can do it super simple. Just create a class an pass it through providers property or through bootstrap For example // Alternative 1 var Service = ng.core.Class({

What object javascript function is bound to (what is its “this”)?

≯℡__Kan透↙ 提交于 2019-11-26 21:00:48
I know that inside the function it is this . var func = function { return this.f === arguments.callee; // => true, if bound to some object // => false, if is bound to null, because this.f === undefined } var f = func; // not bound to anything; var obj = {}; obj1.f = func; // bound to obj1 if called as obj1.f(), but not bound if called as func() var bound = f.bind(obj2) // bound to obj2 if called as obj2.f() or as bound() Edited: You can't actually call obj2.f() as f doesn't become a property of obj2 edit end. The question is: how to find the object, that the function is bound to, outside of