scope

Objective C scope problem

送分小仙女□ 提交于 2019-12-25 09:18:11
问题 I have the following Obj C function that works properly: NSString* myfunc( int x ) { NSString *myString = @"MYDATA"; return myString; } However if I add code to update a UIImage the compile fails with image1 being unknown. image1 is valid: it's set up in the .h, synthesized and that exact line of code works in a method below this function. Only when I move the line of code up to this function does it fail. NSString* myfunc( int x ) { NSString *myString = @"MYDATA"; image1.image = [UIImage

Variable Scope: How VBA Decides When to Override Variables

喜欢而已 提交于 2019-12-25 08:49:50
问题 I have the following VBA code. Option Explicit Sub problem1() Dim speedmph As Double, speedkph As Double, speedfts As Double speedmph = Val(InputBox("Enter a speed (mph)")) Call convert(speedmph, speedkph, speedfts) MsgBox "The speed is " & speedkph & " km/hr and " & speedfts & "ft/s." End Sub Sub convert(speedmph, speedkph, speedfts) speedkph = speedmph * 1.609 speedfts = speedmph * 1.467 End Sub I've noticed that when I called the convert procedure as it is shown above, it worked. But if I

Defining variable after assigning them value in Python 2.7

烂漫一生 提交于 2019-12-25 08:28:46
问题 I get this out put =============================== RESTART: Shell =============================== >>> Warning (from warnings module): File "E:/Python/Roy Progs/test.py", line 2 global x SyntaxWarning: name 'x' is assigned to before global declaration >>> ==================== RESTART: E:/Python/Roy Progs/test.py ==================== 10 >>> when I run this code. x=5 global x x=10 print x Yes I know that defining a variable after assigning it a value is absurd, however python seems to understand

Referencing “this” inside setInterval/setTimeout within object prototype methods

我是研究僧i 提交于 2019-12-25 08:20:07
问题 Normally I'd assign an alternative "self" reference when referring to "this" within setInterval. Is it possible to accomplish something similar within the context of a prototype method? The following code errors. function Foo() {} Foo.prototype = { bar: function () { this.baz(); }, baz: function () { this.draw(); requestAnimFrame(this.baz); } }; 回答1: Unlike in a language like Python, a Javascript method forgets it is a method after you extract it and pass it somewhere else. You can either

NodeJS Variable Scope: Preventing accessing global variables

送分小仙女□ 提交于 2019-12-25 07:58:47
问题 Let's say I got a global variable called myData. It was declared as myData = 1; at the beginning of a script. Goal: I want to create a single module that will not have access this myData in any way. myData must remain global in other modules. Note: Yes, I already do know that I could require myData in every page where I need it but that's not what I'm looking for. Attempts: To do that, at the very beginning of the module, I wrote: var myData; . The module could no longer access myData

AngularJS - Empty option in select with ajax source

て烟熏妆下的殇ゞ 提交于 2019-12-25 07:49:48
问题 I have a select element that should be filled with some options that I need to retrieve from an API call, then set the first one as selected. But Angular creates an empty option at first position and I don't know how to delete it. Here's my code: HTML <select class="form-control" ng-model="selectedPositionFamily"> <option ng-repeat="pf in positionFamilies" ng-value="pf.uuid">{{pf.name}}</option> </select> Controller function Controller($scope, PositionFamilyService) { $scope.positionFamilies

Swift - Use of unresolved identifier

别等时光非礼了梦想. 提交于 2019-12-25 06:59:04
问题 I create all the variables within the same function. But at the end of the function I can't reach the constant even though it was created in the same function. When I write "self.resultLabel.text = weather" at the end, Xcode shows me an error use of unresolved identifier 'weather' I know how to fix it. I need to initiate 'weather' just after the task method starts and set it to "" and then I should change its value in the function but even if I don't do it and I create it in the if closures,

why is global variable not accessible even if local variable is defined later in code [duplicate]

£可爱£侵袭症+ 提交于 2019-12-25 06:54:11
问题 This question already has answers here : Javascript function scoping and hoisting (16 answers) Closed 5 years ago . why does the following code segment generate the following output? code segment: var a = 10; function(){ console.log(a); var a = 5; } output: undefined 回答1: Because variable is hoisted at top and in your function you have declared the variable var a = 5 which is same as following: var a = 10; function(){ var a; // a = undefined console.log(a);//a is not defined so outputs

getJSON and variable scope in javascript

孤街醉人 提交于 2019-12-25 04:56:17
问题 In order to make function calls to our back-end php code we've implemented something called an ActionProxy like this: function ActionProxy(action, input, callback){ $.post("ActionProxy.php?method="+action, { data: input}, function(data, textStatus, XMLHttpRequest){ //return data.ResponseWhatever } }); The problem we're having is that using data outside the ActionProxy is impossible due to variable scope limitations (we assume), setting var res = data.ResponseWhatever or return data

Shell output redirection inside a function

本秂侑毒 提交于 2019-12-25 04:51:49
问题 function grabSourceFile { cd /tmp/lmpsource wget $1 > $LOG baseName=$(basename $1) tar -xvf $baseName > $LOG cd $baseName } When I call this function The captured output is not going to the log file. The output redirection works fine until I call the function. The $LOG variable is set at the top of the file. I tried echoing statements and they would not print. I am guessing the function captures the output itself? If so how do push the output to the file instead of the console. (The wget