ecmascript-5

How to simplify JavaScript/ECMAScript array literal production?

元气小坏坏 提交于 2019-12-13 17:44:27
问题 I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC and have problems with the ArrayLiteral production. ArrayLiteral : [ Elision_opt ] [ ElementList ] [ ElementList , Elision_opt ] ElementList : Elision_opt AssignmentExpression ElementList , Elision_opt AssignmentExpression Elision : , Elision , I have three questions, I'll ask them one by one. I have tried to simplify/to rewrite the ArrayLiteral production depicted above and finally arrived to the following production

javascript this of the outer function of closure having a bound 'this'

爷,独闯天下 提交于 2019-12-13 17:40:36
问题 I am having trouble to get my head around this one. I am aware of scope chaining, callbacks in javascript, the value of this in the callbacks and hence the arrow functions. In javascript, closures have access to variables of the enclosing function via the scope chain. So why the closure does not access the 'this' bound via Function.prototype.bind to the parent function of closure ? Is the variable 'this' not a part of the scope chain? Ran the following code inside the chrome console : a = 4;

Cypress.io: Anyway to test for specific scroll amount?

有些话、适合烂在心里 提交于 2019-12-13 15:22:02
问题 Wanted to know if there is some way to test for scroll amount, within a certain range with Cypress.io. More Specifically Starting from top of page, press button Page scrolls down to a certain height Test whether scroll height is correct within a certain range My attempt: The way I assume would be best is to test that would to test out, that a current div is not within the viewable area of phone screen. Then to scroll down so it does become viewable. cy.get('#angular-projects').should('not.be

JavaScript eval(“{}”) return behavior?

这一生的挚爱 提交于 2019-12-13 13:35:53
问题 According to the ECMA-262 Specification, the following statements return 1 : eval("1;;;;;") eval("1;{}") eval("1;var a;") Ensuring that: The value of a StatementList is the value of the last value producing Statement in the StatementList. Can you explain these different returns ? eval("{}") // undefined eval("var a={}; a;") // {} eval("var a={};") // undefined What is the difference between 1; and {}; ? 回答1: Left alone, {} is interpreted as a block , not an object. It contains no statements,

ios9 Safari miscalculating sum

心已入冬 提交于 2019-12-13 13:06:20
问题 I have some code that calculates the sum of key/values in a hash in a loop. It appears to be calculating the sum in a different manner on ios9 Safari compared with anywhere else. Although I can find a way to fix this individual use case, we use this type of syntax throughout our large code base, so I am looking for some understanding of why this is happening in ios9 if there is a way to globally fix it that would be applicable to all objects that might have a Vue __ob__ object on them. Try

How to make mixins work in react es6?

别来无恙 提交于 2019-12-13 01:34:24
问题 I am learning meteor and reactjs. I have encountered to mixins functionality. I am using es6 where mixin is removed. How can i now enjoy the functionality of mixins in my react es6 code? Here is a code mixins used Signupform = React.createClass({ mixins: [ReactMeteorData], getMeteorData(){ let data = {}; data.currentUser = Meteor.user(); return data; }, getInitialState(){ return { message: '', messageClass: 'hidden' } }, render(){ } }); can't use mixins so how can i make this code work import

Avoid adding methods and properties to custom object

本秂侑毒 提交于 2019-12-12 22:15:40
问题 I'm using a base custom object extended with prototype function Person() {} Person.prototype.Name = ""; Person.prototype.Lastname = ""; var NewPerson= new Person(); NewPerson.Name = "Nancy"; NewPerson.Lastname = "Drew"; //<--- right way NewPerson.lastname = "Drew"; //<--- wrong property I need to avoid to add new properties and methods in a defined object because it would generate silent errors and bugs. I know that javascript has a terrible way to manage classes/objects, but there's a way to

Incrementing object id automatically JS constructor (static method and variable)

给你一囗甜甜゛ 提交于 2019-12-12 18:18:57
问题 I am newbie in JavaScript, I have an idea, to create class (function), I know how it works in JS (prototypes and so on), but I need to do something like incrementing Id in databases. My idea is to create static method, I think closure will suit great here and whenever new object is created it should return incremented id. I don't know what is the right way to implement this, or maybe this is bad practice. Please provide simple example. 回答1: Closure is a good idea: var MyClass = (function() {

Function parseInt (1/10000000) returns 1. Why?

混江龙づ霸主 提交于 2019-12-12 10:54:38
问题 Why parseInt(1/10000000) results 1 , when parseInt(1/1000000) result is 0 ? I need some analog to Java's int casting like int i = -1/10000000; , Which is 0 . Should I use Math.floor for positive and Math.ceil for negative? Or is there another solution? 回答1: At first the question seems interesting. Then I looked at what 1/10000000 is. < 1/10000000 > 1e-7 Therefore: < parseInt("1e-7"); // note `parseInt` takes a STRING argument > 1 If you want to truncate to an integer, you can do this:

Are there semicolon insertion dangers with continuing operators on next line?

走远了吗. 提交于 2019-12-12 09:28:57
问题 Historically, I like to break expressions so that the "it's clearly incomplete" bias is shown on the continued line: var something = foo + bar + baz(mumble); This is an attitude that comes from working in languages which need semicolons to terminate expressions. The first line is already obviously incomplete due to no-semicolon, so it's better to make it clear to the reader that the second line is not complete. The alternative would be: var something = foo + bar + baz(mumble); That's not as