ecmascript-5

How do I call the Tamarin ESC Compiler from AS3 Code?

微笑、不失礼 提交于 2019-12-04 12:15:44
I'm trying to call Tamarin's ESC Compiler from AS3 code. I've got the ESC Compiler byte code loaded in Flash Player, but when I call it, the ESC Compiler always returns the same do nothing byte code, no matter what source code I feed it. The human readable ESC code looks like this: function compileStringToBytes(input, context="(string)", start_line=1) { let [_,_,res] = compile( (function () input), (function (abc) abc.getBytes()), context, start_line ); return res; } I'm calling it using the following AS3 code: var compile:Function = getDefinitionByName("ESC::compileStringToBytes") as Function

Button to show choose a file to upload dialog box

风格不统一 提交于 2019-12-04 11:57:44
问题 Instead of using an input type="file" html tag, is it possible to bring up a choose a file to upload dialog box by clicking a input type="button" ? Then when a file is selected from the choose a file to upload dialog box, the file path gets inserted into a regular html input type="text" tag? I've seem that gmail does something similar but not with buttons and text inputs, they simply have a link add file or something like that. When that link is clicked, it shows the select file(s) to upload

Avoiding .call() and .apply() using .bind()

只愿长相守 提交于 2019-12-04 10:31:21
问题 I'm looking for a way to accomplish a certain task and that is, going from jQuery.when.apply( null, promiseArray ).done(...) to when( promiseArray ).done(...) As you might know, .bind() can get used to create something like default arguments and also doing some quite nifty stuff. For instance, instead of always calling var toStr = Object.prototype.toString; // ... toStr.call([]) // [object Array] we can do it like var toStr = Function.prototype.call.bind( Object.prototype.toString ); toStr([]

Why are logical operators in JavaScript left associative?

霸气de小男生 提交于 2019-12-04 08:54:27
问题 The logical AND and OR operators are the only lazy operators in JavaScript along with the ternary conditional operator. They are tested for short-circuit evaluation using the following rules: false && anything === false true || anything === true This is the same way it is implemented in Haskell: (&&) :: Bool -> Bool -> Bool False && _ = False True && x = x (||) :: Bool -> Bool -> Bool True || _ = True False || x = x However according to MDN logical operators in JavaScript are left associative

Why are anonymous function expressions and named function expressions initialized so differently?

◇◆丶佛笑我妖孽 提交于 2019-12-04 08:26:54
I'm looking at section 13 or the ECMAScript specification (v. 5). An anonymous function expression is initialized as follows: Return the result of creating a new Function object as specified in 13.2 with parameters specified by FormalParameterListopt and body specified by FunctionBody. Pass in the LexicalEnvironment of the running execution context as the Scope. Pass in true as the Strict flag if the FunctionExpression is contained in strict code or if its FunctionBody is strict code. this logic is very similar to how a function declaration is initialized. However, notice how different

argumental reference inconsistency in javascript

断了今生、忘了曾经 提交于 2019-12-04 05:56:57
问题 I have recently encountered a nasty issue in JS. Let say we pass a map, an array of objects to a function f. var o=[{a:0}]; function f(a){ for(var i in a){ if (a.hasOwnProperty(i)){ a[i]=null; } } return a; }; var outp=f(o); alert(outp[0]+" === "+o[0]+" : "+(outp[0]===o[0])); // here we expect loose equality, and equality in type, //furthermore it should identically equal as well, and we got right! But, we can not pass total responsibility of an object to a function as argument, same like in

How can “new new Something” produce valid results in JavaScript?

大憨熊 提交于 2019-12-04 03:24:29
问题 I'm currently developing a JavaScript parser and study the ECMAScript 5.1 specification. Here's a question which puzzles me at the moment. § 11.2 Left-Hand-Side Expressions defines the following NewExpression production: NewExpression : MemberExpression new NewExpression If I read it correctly, then the NewExpression may be something like new new Something (Actually, any amount of new s.) This puzzles me completely. How could new Something potentialy return anything you could once again new ?

JSHint won't let me use 'forEach' in a 'for' loop

淺唱寂寞╮ 提交于 2019-12-04 02:30:15
I have an object with arrays as values. people = { 'steve':['foo','bar'], 'joe':['baz','boo'] } For each key, I would like to loop over the values in the corresponding array. Simple enough: for ( var person in people ) { person.forEach( function(item) { console.log(item) }) } But JSHint complains: Don't make functions within a loop. Is this truly an issue with my code? I quite like the short ES5 for loop syntax. Do I need to use the ES3 style or change my code in some other way? T.J. Crowder There are two issues there, the one that JSHint is warning you about, and a more fundamental one. The

EcmaScript-6 backward compatibility

淺唱寂寞╮ 提交于 2019-12-04 00:34:36
问题 I am curious to understand/figure-out if the ECMAScript-6 new-changes will work on the old browsers or not. Why I am asking this question is: I remember the introduction of 'use strict'; in ECMAScript-5, it was meant for the compatibility with the old versions. That means the old browsers will keep working fine and they will just ignore it when they encounter the 'use strict'; statement while parsing the new JavaScript code. And the new JS-engines will treat the statement 'use strict'; in

JavaScript: Can ECMAScript 5's Strict Mode (“use strict”) be enabled using single quotes ('use strict')?

删除回忆录丶 提交于 2019-12-03 22:03:35
JavaScript doesn't care if your Strings are double-quoted "double" or single-quoted 'single' . Every example of ECMAScript 5's strict mode has it enabled by "use strict" in double-quotes. Can I do the following (single-quotes): alert(function(){ 'use strict'; return !this; }()); This will return true if Strict mode is enabled, and false if it is not. Felix Kling For you, without using a browser that supports strict mode : A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either the exact character sequences "use strict" or 'use strict' . A Use