scope

What is the true meaning of pass-by-reference in modern languages like Dart?

落爺英雄遲暮 提交于 2020-05-15 08:18:07
问题 Working with Futures in Dart, I've come across an interesting issue. import 'dart:async'; class Egg { String style; Egg(this.style); } Future cookEggs(List<Egg> list) => new Future(() => ['omelette','over easy'].forEach((_) => list.add(new Egg(_))) ); Future cookOne(Egg egg) => new Future(() => egg = new Egg('scrambled')); void main() { List<Egg> eggList = new List(); Egg single; cookEggs(eggList).whenComplete(() => eggList.forEach((_) => print(_.style)); cookOne(single).whenComplete(() =>

How to use requestAnimationFrame inside a Class object

佐手、 提交于 2020-05-15 02:03:04
问题 I have a class that takes some coordinate and duration data. I want to use it to animate an svg . In more explicit terms, I want to use that data to change svg attributes over a time frame. I'm using a step function and requestAnimationFrame outside the class: function step(timestamp) { if (!start) start = timestamp var progress = timestamp - start; var currentX = parseInt(document.querySelector('#start').getAttribute('cx')); var moveX = distancePerFrame(circleMove.totalFrames(), circleMove

How to use requestAnimationFrame inside a Class object

你离开我真会死。 提交于 2020-05-15 02:00:11
问题 I have a class that takes some coordinate and duration data. I want to use it to animate an svg . In more explicit terms, I want to use that data to change svg attributes over a time frame. I'm using a step function and requestAnimationFrame outside the class: function step(timestamp) { if (!start) start = timestamp var progress = timestamp - start; var currentX = parseInt(document.querySelector('#start').getAttribute('cx')); var moveX = distancePerFrame(circleMove.totalFrames(), circleMove

javascript- Uncaught SyntaxError: Identifier * has already been declared

时光怂恿深爱的人放手 提交于 2020-05-09 19:18:27
问题 console.log(a) //output:ƒ a(){} var a = 1; function a(){}; var a = 10; console.log(a) //output:10 ==================== var a = 1; if(true){ function a(){}; var a = 10; } console.log(a) // this code throws Uncaught SyntaxError: Identifier 'a' has already been declared both above code snippets are same except the if block.why does the latter throws error when its permissible in javascript to delcare same variable twice in the same scope with var as below function a(){}; var a = 10; //no error

How to access field whenever its name is same with local variable?

笑着哭i 提交于 2020-05-09 12:14:28
问题 I have a field and a local variable with same name. How to access the field? Code: String s = "Global"; private void mx() { String s = "Local"; lblB.setText(s); // i want global } In c++ use :: operator like following: ::s Is were :: operator in Java? 回答1: That's not a global variable - it's an instance variable. Just use this : String s = "Local"; lblB.setText(this.s); (See JLS section 15.8.3 for the meaning of this .) For static variables (which are what people normally mean when they talk

How to access field whenever its name is same with local variable?

别来无恙 提交于 2020-05-09 12:13:12
问题 I have a field and a local variable with same name. How to access the field? Code: String s = "Global"; private void mx() { String s = "Local"; lblB.setText(s); // i want global } In c++ use :: operator like following: ::s Is were :: operator in Java? 回答1: That's not a global variable - it's an instance variable. Just use this : String s = "Local"; lblB.setText(this.s); (See JLS section 15.8.3 for the meaning of this .) For static variables (which are what people normally mean when they talk

Scope of variables in “for” loop

戏子无情 提交于 2020-05-09 04:55:08
问题 What I have known so far is, multiple declarations inside a block produce an error message and also uninitialized local variable gives garbage value on printing. But coming across an example of for loop in C has shaken my concept on the scope of variables. Below is the code for the same: #include<stdio.h> int main() { int i; for(int i = 5; i > 0 ; i--){ int i; printf("%d ", i); } } The above code produces the output 0 0 0 0 0 I have two questions A for loop is considered as one block then how

Why is a local function not always hidden in C#7?

 ̄綄美尐妖づ 提交于 2020-05-07 21:48:05
问题 What I am showing below, is rather a theoretical question. But I am interested in how the new C#7 compiler works and resolves local functions. In C#7 I can use local functions. For example (you can try these examples in LinqPad beta): Example 1: Nested Main() void Main() { void Main() { Console.WriteLine("Hello!"); } Main(); } DotNetFiddle for Example 1 Rather than calling Main() in a recursive way, the local function Main() is being called once, so the output of this is: Hello! The compiler

Why is a local function not always hidden in C#7?

假如想象 提交于 2020-05-07 21:48:04
问题 What I am showing below, is rather a theoretical question. But I am interested in how the new C#7 compiler works and resolves local functions. In C#7 I can use local functions. For example (you can try these examples in LinqPad beta): Example 1: Nested Main() void Main() { void Main() { Console.WriteLine("Hello!"); } Main(); } DotNetFiddle for Example 1 Rather than calling Main() in a recursive way, the local function Main() is being called once, so the output of this is: Hello! The compiler

Why is a local function not always hidden in C#7?

白昼怎懂夜的黑 提交于 2020-05-07 21:42:59
问题 What I am showing below, is rather a theoretical question. But I am interested in how the new C#7 compiler works and resolves local functions. In C#7 I can use local functions. For example (you can try these examples in LinqPad beta): Example 1: Nested Main() void Main() { void Main() { Console.WriteLine("Hello!"); } Main(); } DotNetFiddle for Example 1 Rather than calling Main() in a recursive way, the local function Main() is being called once, so the output of this is: Hello! The compiler