scope

In ActionScript 3, how can I pass the current value of an array in a loop to an event listener

雨燕双飞 提交于 2019-12-10 11:42:19
问题 Code Example: var gospels : Array = ["john", "mark", "matthew", "paul"]; for each (var book : String in gospels) { var loader : URLLoader = new URLLoader(); loader.load(new URLRequest("http://example.com/" + name)); trace(book) // outputs current value of array loader.addEventListener(Event.COMPLETE, function(e : Event) : void { trace(book); // prints paul 4 times }); } How can I get the event listener to use the value of the array in the loop when the event listener's function was called? I

dart method calling context

元气小坏坏 提交于 2019-12-10 11:24:51
问题 I used the below to see how dart calls methods passed in to other methods to see what context the passed in method would/can be called under. void main() { var one = new IDable(1); var two = new IDable(2); print('one ${caller(one.getMyId)}'); //one 1 print('two ${caller(two.getMyId)}'); //two 2 print('one ${callerJustForThree(one.getMyId)}'); //NoSuchMethod Exception } class IDable{ int id; IDable(this.id); int getMyId(){ return id; } } caller(fn){ return fn(); } callerJustForThree(fn){ var

Rails 4 - Pundit - how to write a scope

旧巷老猫 提交于 2019-12-10 11:09:19
问题 Im trying to learn how to use Pundit with Rails 4. I have been trying to learn this for the last 2 years and am slowly making a tiny bit of progress. I am also trying to learn how to write scopes. I'm still trying to figure out how to translate advice into plain english so that I can begin to understand. I'm getting stuck at the intersection of the scopes pundit policies use and the general scope class that I can write in a model. I have models for Uer, Profile and Project. The associations

Python 3 : Sharing variables between methods in a class

泄露秘密 提交于 2019-12-10 10:46:00
问题 Looking for how to make a variable set by one Method/function in a class accessible to another method/function in that same class without having to do excess (and problematic code) outside. Here is an example that doesn't work, but may show you what I'm trying to do : #I just coppied this one to have an init method class TestClass(object): def current(self, test): """Just a method to get a value""" print(test) pass def next_one(self): """Trying to get a value from the 'current' method""" new

Mootools class variable scope

烂漫一生 提交于 2019-12-10 10:43:28
问题 Take this class: var MyClass = new Class({ Implements: [Events, Options], initialize: function() { this.a = 1; }, myMethod: function() { var mc = new differentClass({ events: { onClick: function() { console.log(this.a); // undefined (should be 1, 2, 3 etc) this.a ++; } } }); } }); How do I keep the value of this.a ? I am basically trying to draw a line (using canvas) from the last point to the co-ordinates just clicked. [EDIT] I dont want to bind this as it's bad apparently and it will over

google sign-in auth2 customize scope without openid

我与影子孤独终老i 提交于 2019-12-10 10:24:32
问题 I want to customize the scope to allow only "email" and "profile", without "openid" because I would like to making it asking only to access to email and basic profile info. I tried to do it using the meta: <meta name="google-signin-scope" content="email profile"> or the js: gapi.auth2.init({ client_id: 'xxxxxxxxx.apps.googleusercontent.com', scope: 'email profile' }); But it does not work: in the generated URL there is always the "openid" scope... How can I "reset" the scope, and allow only

What is the scope of a java variable in a block? [duplicate]

若如初见. 提交于 2019-12-10 10:21:50
问题 This question already has answers here : Why does Java not have block-scoped variable declarations? (6 answers) Closed 2 years ago . I know in c++ variables have block scope, for example, the following code works in C++ void foo(){ int a = 0; for(int i = 0; i < 10; ++i){ int a = 1; //re-define a here. } } but this snippet doesnt work in java, it reports "duplicate local variable a", does it mean java variables dont have BLOCK scope? 回答1: java variables do have a block scope but if you notice

Unusual scope resolution operator

大憨熊 提交于 2019-12-10 10:17:52
问题 While refactoring some C++ code today I got some code which boils down to the following class x { public: void x::y(); }; Does the x:: scope resolution operator do anything here, is it a bug, or is it something else. My best guess is that it is an artefact left over by some autocomplete but I'm curious to know if I'm missing anything. Compiler in use is VS2010 SP1. 回答1: It's a bug, and most compilers will reject it. For example, GCC says prog.cpp:4:10: error: extra qualification ‘x::’ on

Default value of the function parameter is “passing_parametr”*2

≯℡__Kan透↙ 提交于 2019-12-10 10:09:38
问题 I wrote the following: #include <stdio.h> int foo(int x, int y=2*x) { return y; } int main() { printf("%d\n",foo(5)); } But I've compile-time error error: local variable ‘x’ may not appear in this context But I'm expected that it will be OK, because 3.3.4/1: In a function declaration, or in any function declarator except the declarator of a function definition (8.4),names of parameters (if supplied) have function prototype scope, which terminates at the end of the nearest enclosing function

Is it safe to access a variable declared in an inner scope by pointer?

时光毁灭记忆、已成空白 提交于 2019-12-10 09:44:50
问题 The program below prints root 3 next 11 However, I am not sure if the program keeps root.next until the end of the program. #include<stdio.h> typedef struct sequence { int x; sequence* next; }sequence; int main() { sequence root; root.x = 3; { sequence p; p.x = 11; root.next = &p; } printf("root %d\n",root.x); printf("next %d\n",root.next->x); return 0; } 回答1: The scope of p ends at the closing bracket. { sequence p; p.x = 11; root.next = &p; } <---- here When you call printf("next %d\n",root