ecmascript-5

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

狂风中的少年 提交于 2019-11-28 01:21:16
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. 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({ constructor : function() {}, someFunction : function() { console.log('Some function'); } }) // Alternative 2

Regex only capturing last instance of capture group in match

痴心易碎 提交于 2019-11-28 01:17:57
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 abcdefg . If I change the expression to \[((?:\\{2}|\\\]|[^\]])*)\] , then I get the result that I want. So

Function Declarations Within Blocks according to the Google JavaScript style guide

元气小坏坏 提交于 2019-11-27 23:17:02
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 (?) function Constructor() { function Shout () { alert('THE BEST UX IS IN ALL CAPS.'); } } RIGHT (?)

Why can I set [enumerability and] writability of unconfigurable property descriptors?

一曲冷凌霜 提交于 2019-11-27 22:31:04
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty states: configurable : True if and only if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object. Defaults to false . So, I have a var x = Object.defineProperty({}, "a", { value:true, writable:true, enumerable:true, configurable:false }); Now I can play with x.a = false , for(i in x) etc. But even though the descriptor is should be unconfigurable, I can do Object.defineProperty(x, "a", {writable:true}); // others defaulting to false Object

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

元气小坏坏 提交于 2019-11-27 22:29:02
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 no matter where it is called. }()); Now, if these are called within the context of "use strict"

John Resig's simple class instantiation and “use strict”

爷,独闯天下 提交于 2019-11-27 21:55:49
问题 Reference : http://ejohn.org/blog/simple-class-instantiation/ // makeClass - By John Resig (MIT Licensed) function makeClass(){ return function(args){ if ( this instanceof arguments.callee ) { if ( typeof this.init == "function" ) this.init.apply( this, args.callee ? args : arguments ); } else return new arguments.callee( arguments ); }; } I was wondering, if there are any ECMAScript 5 compliant way to implement the same functionality. The problem is, accessing arguments.callee is deprecated

What Internal Property In ECMAScript is defined for?

南楼画角 提交于 2019-11-27 21:32:05
What the Internal Property in ECMAScript is defined for ? What does the spec mean by This specification uses various internal properties to define the semantics of object values.These internal properties are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. Does it mean that Internal properties defined by ECMAScript are not available for programming. They are used in the implementation of the javascript engine ? Internal properties define the behavior of code as it executes but are not accessible via code. ECMAScript defines many

Usage of rest parameter and spread operator in javascript

情到浓时终转凉″ 提交于 2019-11-27 19:29:26
What's the usage of rest parameter that will be added in ECMAScript 6? For example, in ECMAScript 5 you can do the following to get an array of parameters starting from the second element: // ES 5 store('Joe', 'money'); store('Jane', 'letters', 'certificates'); function store(name) { var items = [].slice.call(arguments, 1); //['money'] in first case items.forEach(function (item) { vault.customer[name].push(item); }); } and that will be equivalent to the following code in ECMAScript 6: // ES 6 store('Joe', 'money'); store('Jane', 'letters', 'certificates'); function store(name, ...items) {

Why can I set [enumerability and] writability of unconfigurable property descriptors?

拜拜、爱过 提交于 2019-11-27 19:10:58
问题 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty states: configurable : True if and only if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object. Defaults to false . So, I have a var x = Object.defineProperty({}, "a", { value:true, writable:true, enumerable:true, configurable:false }); Now I can play with x.a = false , for(i in x) etc. But even though the descriptor is should be

Working around IE8's broken Object.defineProperty implementation

 ̄綄美尐妖づ 提交于 2019-11-27 19:03:42
Consider the following code, using ECMAScript5's Object.defineProperty feature: var sayHi = function(){ alert('hi'); }; var defineProperty = (typeof Object.defineProperty == 'function'); if (defineProperty) Object.defineProperty(Array.prototype,'sayHi',{value:sayHi}); else Array.prototype.sayHi = sayHi; var a = []; a.sayHi(); This works for Chrome and Firefox 4 (where defineProperty exists), and it works for Firefox 3.6 (where defineProperty does not exist). IE8, however, only partially supports defineProperty . As a result, it attempts to run the Object.defineProperty method, but then fails