scope

clearInterval() not working [duplicate]

喜你入骨 提交于 2019-12-20 16:14:37
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: JS - How to clear interval after using setInterval() I have a function that changes the font-family of some text every 500 ms using setInterval (I made it just to practice JavaScript.) The function is called by clicking on an "on" button and the interval is supposed to be cleared using a separate button, "off". However, the "off" button doesn't actually clear the interval, it just continues. I suspect that this

Beginning Haskell - getting “not in scope: data constructor” error

和自甴很熟 提交于 2019-12-20 11:35:33
问题 I'm going through the problems in the Haskell O'Reilly book. The problem I am working on is Using the binary tree type that we defined earlier in this chapter, write a function that will determine the height of the tree. The height is the largest number of hops from the root to an Empty. For example, the tree Empty has height zero; Node "x" Empty Empty has height one; Node "x" Empty (Node "y" Empty Empty) has height two; and so on. I'm writing my code in a file called ch3.hs. Here's my code:

Declaring variables within FOR loops

五迷三道 提交于 2019-12-20 10:12:11
问题 A weird bug was occurring in production which I was asked to look into. The issue was tracked down to a couple of variables being declared within a For loop and not being initialized on each iteration. An assumption had been made that due to the scope of their declaration they would be "reset" on each iteration. Could someone explain why they would not be)? (My first question, really looking forward to the responses.) The example below is obviously not the code in question but reflects the

C# - anonymous functions and event handlers

情到浓时终转凉″ 提交于 2019-12-20 10:06:18
问题 I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new List<IWFResourceInstance>(); this.FoundStep += delegate(object sender, WalkerStepEventArgs e) { if (e.Step.ResourceType == res) retval.Add(e.Step); }; this.Start(); return retval; } Notice how I register my event member (FoundStep) to local in-place anonymous function. My question is: when the function 'FindStepByType' will end - will the anonymous function be

How can I localize Perl variables in a different stack frame?

走远了吗. 提交于 2019-12-20 10:02:12
问题 I have some auto-generated code which effectively writes out the following in a bunch of different places in some code: no warnings 'uninitialized'; local %ENV = %ENV; local $/ = $/; local @INC = @INC; local %INC = %INC; local $_ = $_; local $| = $|; local %SIG = %SIG; use warnings 'uninitialized'; When auto-generating code, some argue that it's not strictly necessary that the code be "beautiful", but I'd like to pull that out into a subroutine. However, that would localize those variables in

What is the difference between “File scope” and “program scope”

不羁岁月 提交于 2019-12-20 09:39:56
问题 A variable declared globally is said to having program scope A variable declared globally with static keyword is said to have file scope. For example: int x = 0; // **program scope** static int y = 0; // **file scope** static float z = 0.0; // **file scope** int main() { int i; /* block scope */ /* . . . */ return 0; } What is the difference between these two? 回答1: In C99, there's nothing called "program scope". In your example variable x has a file scope which terminates at the end of

Angularjs: how to pass scope variables to a directive?

限于喜欢 提交于 2019-12-20 09:30:32
问题 I am trying to use directive to create and append several tags to a <div> as shown below: module.directive('createControl', function(){ return function(scope, element, attrs){ console.log(attrs.createControl); // undefined } }); <div class="control-group" ng-repeat="(k, v) in selectedControls"> <div create-control="{{ v.type }}"></div> </div> In attrs I have this construction: $$element: b.fn.b.init[1] $$observers: Object $attr: Object createControl: "date" style: "margin-right: 15px" __proto

Rails Scope returns all instead of nil

一笑奈何 提交于 2019-12-20 08:57:02
问题 I'm running into a strange issue creating a scope and using the first finder. It seems as though using first as part of the query in a scope will make it return all results if no results are found. If any results are found, it will correctly return the first result. I have setup a very simple test to demonstrate this: class Activity::MediaGroup < ActiveRecord::Base scope :test_fail, -> { where('1 = 0').first } scope :test_pass, -> { where('1 = 1').first } end Note for this test, I have set

typedef stuct problem in C

不想你离开。 提交于 2019-12-20 07:40:03
问题 I am facing a weird problem I have defined I a structure in a C header file: typedef struct iRecActive{ char iRecSID[32]; unsigned char RecStatus; int curSel; }iRecAcitve_t; but when I use the same structure in another file, the compiler doesn't recognize the structure even though I have double checked that I have included its header file. Following is the error : : error C2065: 'iRecActive_t' : undeclared identifier Following is the full code of the file where I have defined the structure

What scope is 'this' of a node.js object when it gets called at the top-level?

假如想象 提交于 2019-12-20 07:26:48
问题 I read "Why and how to bind methods in your React component classes?" and grabbed the basic idea of how different is this by the scopes it gets called. I made a simple class to test this. class Something { constructor(some) { this.some = some; } print() { console.log( "print from ", this, this === undefined ? "!!this is undefined!!" : this.some ); } } From what I understood, the scope of this can be different although it is from the same object (instance). const some = new Something("is");