scope

jQuery bind inside a for loop variable scope

帅比萌擦擦* 提交于 2019-12-12 04:59:46
问题 I know this question has been asked many times but I haven't been able to resolve from what I found on Stack O. Here is my code for(var i=0; i<retrievedSearchesListLength; i++){ retrievedSearchesListProv = retrievedSearchesList[i].searchId; retrievedSearchesListType = retrievedSearchesList[i].searchParameters; function getEventHandlerFunction(a){ $J.cookies.set('ps_clickedsearch',a); } $J('#submitSearch'+i).bind('click',getEventHandlerFunction(retrievedSearchesListType)); } Everytime the

How to use scope in JavaScript for Function constructor?

社会主义新天地 提交于 2019-12-12 04:58:55
问题 If I were to make a new function using the Function constructor, how could I give it a non-temporary scope to access besides window (meaning the scope only has to be evaluated once, not every time the function is called)? The purpose is to construct multiple variables that require some pretty costly calculations, and I don't want to reconstruct them every time the function is called, but I also don't want to store them in window . Any ideas? 回答1: For the above described purpose, you use

Closures in recursion

只谈情不闲聊 提交于 2019-12-12 04:55:29
问题 i have this two recursive functions in javascript. first function returns digits of the input number in right to left order second function returns them in left to right order. function first(n){ if(n > 0){ m = Math.floor( n/10 ); v = ( n - m * 10 ) + " " + first(m); return v; } return ""; } function second(n){ if(n > 0){ m = Math.floor( n/10 ); v = second(m) + " " + ( n - m * 10 ); return v; } return ""; } result of the first function is 7 6 1 result of the second function is 1 16 167 but I

Global scope variable unchanging in python

╄→гoц情女王★ 提交于 2019-12-12 04:54:49
问题 In this code money = .3 Things = ["Nothing"] def main(): print "go to buy things" print "Current Money %s" % (money) print "Things you have:" for item in Things: print item wait = raw_input() buythings(money) def buythings(money): print "Type Buy to buy things" buy = raw_input() if buy == "buy": money = money - .3 Things.append("Things") main() else: print "you bought nothing" print "" main() Why after buying the things does the money not go down? This has been a problem to me for a while now

How to set a variable in these batch loops?

丶灬走出姿态 提交于 2019-12-12 04:49:18
问题 think I'm getting things confused here. I've got a loop that runs all files in a folder for /f "delims=_" %%J in ('forfiles /p "%%F" /m *.ext /c "cmd /c echo @path"') do start "program" /D "c:\program files\path\to\program" /Wait program -r %%J %%J should represent each file if I've set this up / interpretted this correctly. I have another loop that is looking in the xml code for each of these files and searching for a particular pattern using findstr and parsing out the Name from some tags

javascript keeps looping

一个人想着一个人 提交于 2019-12-12 04:43:15
问题 continuing from here ... since the problem has signifally altered (in my opinion) here is my code for (var i = 0; i < len; i++) { (function () { var queryid = results.rows.item(i).id; //sql primary key var divid = "#" + queryid; //assigned id to divs var pressTimer; $(divid).mouseup(function(){ //func to handle tap + hold clearTimeout(pressTimer) // Clear timeout return false; }).mousedown(function(){ // Set timeout pressTimer = window.setTimeout(function() { alert(divid); $(".somediv").show(

python variable contents changed by function when no change is intended

耗尽温柔 提交于 2019-12-12 04:38:17
问题 Here is a sample of code where a function is run repeatedly with new information for most of the input variables except one, good_ens. The input variable good_ens that should never be changed, gets changed. What is going on here? This defies my understanding of scope. def doFile(infileName, outfileName, goodens, timetype, flen): print('infilename = %s' % infileName) print('outfilename = %s' % outfileName) print('goodens at input are from %d to %d' % (goodens[0],goodens[1])) print('timetype is

Change a variable from outside it's scope [duplicate]

a 夏天 提交于 2019-12-12 04:30:54
问题 This question already has answers here : Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference (6 answers) Closed 3 years ago . function get_all_channels_by_order(){ var foobar = false mysql_connection.connect() mysql_connection.query("SELECT * FROM channels ORDER BY listorder ASC", function(){ foobar = true }) mysql_connection.end() console.log(foobar) } I need foobar to return true but instead it returns false . This is due of course to the

PHP, Variable Scope Question

戏子无情 提交于 2019-12-12 04:21:51
问题 My question is I am using the variable $db in my general script code and within one of my functions. It's purpose is to be the variable that is used for MySQL connections. I have a need inside a function to write some data to the database. In my script I cannot assume that an existing db connection will be open so I open a new one and close it before the function exits. Ever since doing this I am getting an error after the script runs saying the MySQL reference is bad / doesn't exist. The

Python: How do I assign 2 values I return from a function with 1 input as values outside the function?

孤人 提交于 2019-12-12 04:13:19
问题 I'm starting out in python and thought it'd be a good exercise to try to build a function that determines whether an input passed to it is an integer, and if so whether it's positive. At a later stage I plan to reference that function from within a mathematical function that only accepts positive integers. Anyway, this is the function I built: def is_ok(x): #checks if x is a positive integer is_int = False is_pos = False if type(x) == int: is_int = True # if it's an integer, continue to test