ecmascript-5

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

非 Y 不嫁゛ 提交于 2019-11-29 10:47:14
This question already has an answer here: Alternative to arguments.callee 2 answers 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 function name(){ ... function() ... }, but I can't seem to find what to do with the above code. Starting with ECMAScript 3, you

Javascript conditional regular expression if-then-else

萝らか妹 提交于 2019-11-29 06:22:01
I'm trying to limit the entries to a specific format. If the entry has 5500 or 5100 such as 01\01-5500-000-00 then I want to have this: ^[0-9]{2,}\\[0-9]{2}\-[0-9]{4}\-[0-9]{3}\-$ But if the entry has anything other than 5500 or 5100 I want to have this: ^[0-9]{2,}\\[0-9]{2}\-[0-9]{4}\-[0-9]{3}\-[0-9]{2}$ How can this be accomplished with the if then else idea? Conditional regex syntax is not supported by JavaScript regex engine, but it can be worked around with a non-capturing group containing 2 alternatives: One with the positive look-ahead and The second with the reversed, negative look

Clarity on the difference between “LexicalEnvironment” and “VariableEnvironment” in ECMAScript/JavaScript

岁酱吖の 提交于 2019-11-29 04:35:58
Could someone clarify what the difference is between these two, as they exist in the Execution context? It's hard for me to read the ECMA 262 v 5 specification and clearly see the difference. Thank You, Bergi Both are components (of the same type) of Execution Contexts, but they serve distinct purposes ( from the spec ): LexicalEnvironment Identifies the Lexical Environment used to resolve identifier references made by code within this execution context. VariableEnvironment Identifies the Lexical Environment whose environment record holds bindings created by VariableStatements and

Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?

江枫思渺然 提交于 2019-11-29 03:44:55
Is it needed to learn TypeScript for Angular 2? Can Angular 2 be used with plain JavaScript ? Edit: I've seen that the languages used as ES6, ES7, Dart compile to JavaScript to be executed, but I haven't seen any reference to use ES5 JavaScript directly. Yes, you can. Go read this guide . Pressing the ES5 tab on the code examples will show you regular ES5 JavaScript, as apposed to TypeScript. The API preview is, for obvious reasons, incomplete though. So you may not find the ES5 methods listed there yet, and some of it may change before release. Current example of Angular 2.0 main component in

Object.defineProperty polyfill

时光总嘲笑我的痴心妄想 提交于 2019-11-29 02:35:46
I am currently writing a JavaScript API which is based on new features in ES5. It uses Object.defineProperty quite extensively. I have wrapped this into two new functions, called Object.createGetSetProperty and Object.createValueProperty I am however experiencing problems running this in older browsers (such as the dreaded, IE8) Consider the following code: Object.createGetSetProperty = function (object, property, get, set, enumerable, configurable) { if (!Object.defineProperty) throw new Error("Object.defineProperty is not supported on this platform"); Object.defineProperty(object, property,

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

断了今生、忘了曾经 提交于 2019-11-29 02:20:25
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 in strict mode. As I understand it arguments.callee isn't deprecated in strict mode, in which case you

Inconsistent scope of “use strict” on different web browsers (concerning arguments.callee and caller)

北战南征 提交于 2019-11-28 18:45:44
问题 Situation: I found something strange concerning strict mode in Javascript. I am using an external, third-party Javascript library which was minified, has over 4000 lines of code, is not using use strict at all, and is using arguments.callee . I am using use strict in my own code, scoped within a function. When I call one of the functions provided by the library, it throws an error. However, the error is thrown only if I am using use strict the error is thrown in all browsers except Chrome

Is it possible to emulate non-enumerable properties?

对着背影说爱祢 提交于 2019-11-28 18:38:27
ES5 has a enumerable flag. Example Example var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor , pd = getOwnPropertyDescriptor(Object.prototype, "toString"); assert(pd.enumerable === false, "enumerability has the wrong value"); Partial implementation Partial implementation is do-able by having Object.keys and Object.getOwnPropertyNames filter out new non-enumerable properties using the shimmed Object.defineProperty . Introduction This allows for properties to be non enumerable. This clearly means that Example for (var key in {}) { assert(key !== "toString", "I should never print");

when do you use Object.defineProperty()

怎甘沉沦 提交于 2019-11-28 18:15:34
问题 I'm wondering when I should use Object.defineProperty to create new properties for an object. I'm aware that I'm able to set things like enumerable: false but when do you need this really? If you just set a property like myObject.myprop = 5; its descriptors are all set to true, right? I'm actually more curious when you guys use that rather verbose call to .defineProperty() and for what reasons. 回答1: Object.defineProperty is mainly used to set properties with specific property descriptors (e.g

Indirect eval call in strict mode

喜欢而已 提交于 2019-11-28 18:07:28
I understand about how eval() works in non-strict contexts, however the case of using eval() in strict mode has completely befuddled me. When eval() is called directly in the global scope, variables are kept inside the new eval() scope: 'use strict'; eval('var a = 1;'); console.log(a); // ReferenceError: a is not defined However, if I perform an indirect call to eval() in the global scope (should be the same thing, right?), it acts as though it is not in strict mode (if you don't believe me, see this JSFiddle ): 'use strict'; (0, eval)('var a = 1;'); // indirect call to eval console.log(a); //