javascript,jquery,function,global
Because of the way jQuery works. This error is predictable. What is happening, is the declaration of fxn is waiting until the document is actually ready. Where the call to this method is not. So, by attempting this you are in essence trying to call a function that doesn't yet...
I would follow along the lines of Mike's recommendation, but go the full Module pattern route. This will allow you to have "private" functions as well in the event that you want to collect any common functionality. With this solution, I don't see a need for the self variable, unless...
javascript,jquery,javascript-events,event-handling,global
In IE, the event object was a global object, (which is not passed to the handler function) but accessed as a global object. You can also access it as a property of the window object like window.event In in FF and other browsers the event object was passed as an...
javascript,design-patterns,namespaces,global
There is no commonly accepted best way. Sorry. As Pointy said, your method involves creating the MyObj constructor function, which presumably will never be used again, as well as the myApp namespace object. It has at least one other minor disadvantage: you can't prevent yourself or someone else using the...
You can us something like this: class Favorites { var favoritesArray:Array <AnyObject> init(favoritesArray:Array <AnyObject>) { self.favoritesArray = favoritesArray } } and declare it as : var favoritesInstance = Favorites(favoritesArray:["Harpers_Bazaar_Ch_03_15_0000.jpg"]) and call it from anywhere as : let x = favoritesInstance.favoritesArray ...
Sorry to say but you are using the % in way too many places Its use depends on where you are using the variable if it in an expression you do not use % around variables, in most other places you do, next thing is then to know when you're...
I think, you missed to define the array. IMO, what you want is byte GlobalAr[10] = {0}; GlobalAr[0] = 0b00001111; GlobalAr[1] = 0b00001010; and so on. Otherwise, as per your code extern byte GlobalAr[10]; and byte GlobalAr[0] = 0b00001111; you're trying to redefine the GlobalAr array with a different size[10...
python,variables,undefined,global
FTFY #!/usr/bin/python def travel(): travel.totrate=0 def guide(): print"Due to prefer a guide??" print"a guide inperson...rate=1000" print"maps,3g....rate=2000" ch6=raw_input("ENter your choice") if(ch6=="person") or (ch6=="PERSON"): increment = 1000 elif(ch6=="gadget" or ch6=="GADGET"): increment = 2000 else: print "invalid" travel.totrate += increment print travel.totrate guide() travel() You really don't need a global variable at all....
java,class,sockets,global,printwriter
I think this is giving you the NullPointerException ChatPanel.pw.println(ChatPanel.name + " has disconnected from the chat."); because ChatPanel.pw has never been initialized in your code, and therefore is null You should ensure that ChatPanel.pw has been initialized somewhere (maybe within the constructor) inside your ChatPanel class before calling the ChatPanel.pw.println()...
javascript,html,variables,undefined,global
Without reading your code but just your scenario, I would solve by using localStorage. Here's an example, I'll use prompt() for short. On page1: window.onload = function() { var getInput = prompt("Hey type something here: "); localStorage.setItem("storageName",getInput); } On page2: window.onload = alert(localStorage.getItem("storageName")); You can also use cookies but localStorage...
To use a in genTable, either Give genTable a parameter and invoke with it from colNum // in function colNum genTable(a); // a refers to the variable named a // ... function genTable(a) { // a refers to the parameter named a } var a; in a closure that contains...
This is simple enough, don't declare your list outside of the function. Move node_list = [] into your function definition: def scan(ipnet, port): node_list = [] for x in range(1,255): ip = '{0}.{1}'.format(ipnet, x) t = Thread(target=probe, args=(ip, port)) t.start() return node_list Essentially, you want to read up a little...
javascript,variables,global,local
Because when you do foo = 7; it makes a global variable and sets it to 7, even after the function is done it's still 7. You probably want it to be a local variable: (function Test() { var foo = 7; console.log("foo=" + foo); })(); ...
There are multiple issues You cannot have arbitrary code in the body of your class, e.g. the WEAPONS[0] = calls. However, you can initialize the array directly using new Type[]{} syntax. You could also use a static initializer static {} but this is not recommended. Also, you need to use...
c,function,function-pointers,global
Declaration, usually in a .h file but also possible to just copy-paste to a .c file directly (for quick & dirty testing etc, for any real code you should write a proper .h file). Duplicates in same compilation unit are are ok as long as they match. You can use...
My other answer is more about what approach you can take inside your function. Now I'll provide some insight on what to do once your function is defined. To ensure that your function is not using global variables when it shouldn't be, use the codetools package. library(codetools) sUm <- 10...
bash,function,arguments,global
You can use quotes to prevent this. Examples : test() { for i in "[email protected]" do echo "$i" done } test "[email protected]" Output : $ ./test.sh foo "bar baz" foo bar baz Without quotes : test() { for i in [email protected] # no quotes do echo "$i" done } test...
Just wrap everything in a function: function resizeSidebar() { var pageWidth = $('#page').width(), pageWidthFifth = pageWidth / 5, wrapAndSidebar = $('#sidebar-wrap, #sidebar'); wrapAndSidebar.width(pageWidthFifth); } resizeSidebar(); $( window ).resize( function() { resizeSidebar(); } ); Please note I haven't tested this code in the browser, but it's pretty much what you must...
You have to declare the var also global inside the function as described here: https://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html global m = 1; function p = h() global m; m endfunction h() ...
You cannot reassign an array like: board[3][3] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } }; Since you never use board before you try to assign values to it in main() just replace char board[3][3] = { { ' ', '...
This is because in the second case, functions.php is looking to include config.php from within the current path which is /api/. Also, why the global $database declaration if you are going to be calling getDatabase() anyway?...
javascript,canvas,scope,global
I assume the list line is draw();. You are seeing this error because you are calling update(); and draw() before init() is called and set map. Solution: Ensure that update and draw are called after init has been called. For example, by placing the calls inside the load event handler....
python,function,variables,global
You could solve this problem using global variables: see here. However, it's a better practice in Python to use classes, and keep functions that share variables, along with the variables they share, in a particular class. In your code, that would look something like this: class MediumHandler(object): def __init__(self): self.hydro...
java,jvm,global,static-methods
Static methods (in fact all methods) are stored in the PermGen/metaspace and static fields are stored in a special object for each class on the heap, since they are part of the reflection data (class related data, not instance related). If your static variable is a reference to an object...
I have set up a custom class (subclass of UIView) to link a xib file No, you haven't. No such "link" is possible. what am I missing? You're not missing anything, because you've already figured it out! Merely creating a LaunchCustomScreen instance out of thin air (i.e. by saying...
marshalling,global,drools,unmarshalling,kie
Globals are not inserted into the Working Memory, consequently they are not saved with the KieSession's state. Globals have to be inserted every time you restore KieSession's state....
global is evil, please don't use it. I'd use constants for the database parameters: define('DB_NAME', 'MyDatabase'); define('DB_USER', 'root'); define('DB_PASSWORD', '1234'); Then, use require instead of include for your config.php. Your application should not proceed without it....
php,arrays,global,preg-replace-callback
Ok, at the beginning: global $idarray; $idarray=array(); ...
I think you have to look at the life-span of the script When the user hits First button: Form submitted script runs (sets your variable) script terminates (as does all things related) Second button: Form submitted script runs (does not set second variable) script terminates (as does all things related)...
It tells the compiler that binding the name should be performed in the module scope rather than the local scope. It has no use if you're simply mutating the object (e.g. fruits.append('apple')).
Does this solve the problem? def show_entry_fields(): global site, score, master site = e1.get() score = e2.get() master.destroy() At least the print at the end of the program is printing the right answer....
asp.net-mvc,azure,active-directory,global
This solution is not very general, but might be just want you want if you are deploying to Azure Web Sites. You can ask Azure Web Sites to enforce authentication with an AAD before allowing users to reach your site. Basically, you can develop locally WITHOUT any AAD in your...
You can use the singleton design pattern to make a new class that stores all the data you wish to keep across all your activities. http://en.wikipedia.org/wiki/Singleton_pattern Essentially you create a class that only contains a get method. The method creates an instance of an object if there is none or...
python,multithreading,variables,global
You are never changing the global variable output. The variable output in ColorRandomizer.run is a local variable that shadows the global. Insert the line global output a the top of the run function of Color_Randomizer. Remove the return output statement in Color_Randomizer(). Your time.sleep call in the next line is...
javascript,jquery,function,global,encapsulation
$(function() { is just a shortcut to $(document).ready(function() {. In both cases you are inside a function, so as long as you use the var when assigning variables they won't pollute the global scope. Note that you can use multiple ready handlers with no problem....
c,arrays,global-variables,global
#include<stdio.h> #include<conio.h> int sudoku[10][10]; main() { int i,j,n; clrscr(); printf("enter the array size\n"); scanf("%d",&n); printf("enter the values into an array\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&sudoku[i][j]); } } arr(sudoku,n); getch(); } void arr(int sudoku[10[10],int n) { printf("array content are as follows\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d",sudoku[i][j]); } printf("\n"); } } ...
void read_control() { double P, T; ifstream file; string u = "useless data"; file.open("control.inp"); file>> u >> u >> P >> T; file.close(); cout << "Read_control says T = " << T << endl; } The variable T declared here is a local variable for this function and its scope...
Globals are not shared between modules. Your test2 namespace got its own indepdendent reference to the 1 value a references in the other module. Setting a in test1 then rebinds the test.a name to a new object (the 2 integer value), but the test2.a reference is not going to be...
As Ffisegydd points out, there is no such thing as a primitive in Python: everything is an object. You should however note that you are doing two completely different things in those two snippets. In the first, you are rebinding x to the value of x+1. By attempting to assign...
python,python-2.7,global,python-import,python-module
Yeah I guess there is a more elegant way of doing this which will save redundant line of code. Suppose you want to import some modules math, time, numpy(say), then you can create a file importing_modules(say) and import the various modules as from module_name import *, So the importing_modules.py may...
Let's simplify: ;(function(root) { ... }(this)); So, we have a function that takes an argument called root. This function is being immediately invoked (http://benalman.com/news/2010/11/immediately-invoked-function-expression/), and we are passing the value this to it. In this context, this is your global object. If you are using a browser, your global object...
Declare globally: var sidebarHeight, sidebarOffset; Set locally: $(window).on('load', function(){ sidebarHeight = $('.sidebar').height(); sidebarOffset = $('.sidebar').offset().top; }); They won't have a value between their declaration and setting them, so other code which uses them may need to account for that. But if you need them to be in global scope then...
You never call loadGraphics. Call that at the start of main, and your program will probably work. But you'd almost certainly be better off without globals; and in any case, you don't want to define them in a header since that will break the One Definition Rule if you include...
You can change the value of the object reference stored in a DRL global only by using the API: then //... kcontext.getKieRuntime().setGlobal( "deviceCapacity", $snrData.getDeviceCapacity() ); end Clearly, this is ugly and not checked at compile time. You might consider writing a wrapper class IntWrapper { private int value; // getter,...
global,local,scenekit,coordinate
SCNNode exposes the following methods to convert between coordinate spaces: -convertPosition:fromNode: -convertPosition:toNode: -convertTransform:fromNode: -convertTransform:toNode: ...
javascript,global,addeventlistener
Something similar to item 8 in this post is going on I suspect: What is the scope of variables in JavaScript?...
currently your textlistenerlocation function is not being called. So when you hit the submit button, locationGlobal has not yet been defined. The following looks suspicious: locationTxtbox:addEventListener("textListenerLocation",locationTxtbox) the addEventListener should take an event string and then a function to call when the event happens. textListenerLocation is your event handling function, it...
It depends - is the property writable/configurable or not? Infinity is neither, as exposed by the following console log: > Object.getOwnPropertyDescriptor(window,'Infinity') < Object {value: Infinity, writable: false, enumerable: false, configurable: false} However, other global properties, such as frames, are configurable: > Object.getOwnPropertyDescriptor(window,'frames') < Object {value: Window, writable: true, enumerable: true,...
php,jquery,wordpress,global,shortcode
You have to echo variables for them to output columnWidth: <?php echo $masonry_item_width ?>, gutter: <?php echo $masonry_item_padding ?>, As to how to get your values... Wordpress makes plugins such a mess with all these standalone callbacks. Normally I would abhor doing this but I can't think of any other...
A possible work around for this problem is something simple like this: def get_my_list(): return [var1, var2] var1 = False var2 = False print get_my_list() >>> [False, False] var1 = True print get_my_list() >>> [True, False] Then you just use get_my_list() in place of where you had the list before....
variables,tcl,global,argv,argc
You appear to make two wrong assumptions here: If a proc does not use a special argument args in its defintion (see below for more info), it accepts only the fixed number of arguments—exactly matching the number of parameters used in its definition. Each call is checked by the interpreter,...
Because the way the file $lang.php is included, the variable $translation lands as a local variable in a function and not as a global variable as method Strings::translate() expects it. After we discussed in chat and I understood the problem, I can suggest two solutions: Solution 1 (the quick workaround)...
You are missing the namespace: You can add the following at the beginning of your file after your includes (note that in a more complex scenario this could be a problem. see here) using namespace std; or you can specify the namespace each time you are using string: std::string...
php,variables,twig,global,templating
Using Symfony2 configuration If you are using Symfony2, you can set globals in your config.yml file: # app/config/config.yml twig: # ... globals: myStuff: %someParam% And then use {{ myStuff }} anywhere in your application. Using Twig_Environment::addGlobal If you are using Twig in another project, you can set your globals directly...
c#,variables,static,const,global
const and readonly perform a similar function on data members, but they have a few important differences. A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. The...
python-3.x,global-variables,global
It depends on the purpose of that Settings object. If you're doing it for your personal convenience to pass data around then that's the wrong reason. But if your application as various configuration settings / flags that are needed in various places then passing a Settings object around it a...
c++,design-patterns,mfc,const,global
Your inheritance tree essentially defines two different values for the base struct. You don't need inheritance just to define those values, you only need two variables: struct eOfficeExtensions{ const CString WORD_EXTENSION; const CString EXCEL_EXTENSION; const CString WORDPAD_EXTENSION; const INT EXTENSION2007; }; const eOfficeExtensions extensions2003{_T(".doc"), _T(".xls"), _T(".rtf"), 0}; const eOfficeExtensions extensions2007{_T(".docx"),...
angularjs,authentication,user,global
So actually you want to encapsulate a third party service to reduce your dependency on a third party library. Your third party library provides a service $localStorage with some properties you want to access. Here is one way to do so: function YourAuthService($localStorage) { this.isAuthenticated = function () { return...
javascript,arrays,function,variables,global
Of course it would help if you paste more of your code, but first try to change the variable name "values". Edit: I checked your code and screenshot and even tried your code and the output came as expected. It seems you are working on Google Chrome, did you try...
performance,matlab,function,variables,global
Here is a simplified example of how I would go about solving this: function y = example % a1 = -2; a2 = -1; save('example_constants.mat') constants = load('example_constants.mat'); y = fsolve(@(x) myfun(x, constants), [-5;-5]); end function F = myfun(x, c) F = [ 2 * x(1) - x(2) - exp(c.a1...
ruby-on-rails,constants,global,env
The above won't work because the backtick command starts its own shell and ends it so those variables are never included in the rest of your script. I think you'll have to parse the file yourself and add the entries to ENV. I would look at the dotenv gem and...
php,variables,null,return,global
I would check the actual value of $_SESSION['action'], as well as separately echoing out (or var_dump) other variables such as $emp_name for testing / ensuring they are actually populated as you expect. As Jay Blanchard mentioned, using $_SESSION['someVar'] is better than using the global keyword. Found some good info here:...
You can add throw to the UNIVERSAL package (which isn't a good practice). Note that your throw ignores the message and displays just the class name. #!/usr/bin/perl use warnings; use strict; { package UNIVERSAL; sub throw { die shift } } { package MyClass; sub new { bless {}, shift...
twitter-bootstrap,grid,global,area,concrete5
Why not enable bootstrap grids in the template/page type and then add the global areas that you want? Or alternatively create any global area and then add HTML which sets up the bootstrap for you? As so: <div class="row"> <div class="col-md-8 col-xs-12"> <div id="divExampleContent"> <h1 class="decorated"><span>Example1</span></h1> <?php $a = new...
c++,memory-management,global,local
Since the first test run is slower, no matter which it is, then probably the OS takes longer to allocate 4GB and then map it to writable memory on the first pass through. In extremis, it might need to save other things out to swapfile to make RAM available the...
variables,global,protractor,definition
1) There are 3 important keywords: element, browser, and protractor. element is how you select content on the page, browser is how you interact with the browser that you're testing (i.e. browser.get(...)), protractor is a shortcut for you to access static variables defined in the webdriver namespace. For example: browser.get('http://www.someUrl.com');...
ruby-on-rails,ruby,variables,design,global
Rather than passing a @discogs variable around your application, you can create a global object in an initializer like so: config/initializers/discogs.rb DiscogsWrapper = Discogs::Wrapper.new("My awesome web app") Now you can refer to the DiscogsWrapper object in other parts of your application. Example 1: module Artists def self.search(name, wrapper = DiscogsWrapper)...
Ok, so I found the easiest way to do this is to use this class: static class MBW { public static ProjectName.MessageBoxWindow MessageBox_Window = System.Windows.Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MessageBoxWindow) as MessageBoxWindow; } Then just use: MBW.MessageBox_Window to access everything inside that window without having to copy out the long code...
javascript,jquery,jquery-selectors,global
Most of the time you can avoid polluting the global name space by wrapping your code in an immediately executed function expression: (function() { // declare variables here var $_element_1 = ...; // use them here function animate_1() { ... } // register event handlers ... })(); // invoke the...
Your solution could look like this: <?php require_once("rpcl/rpcl.inc.php"); //Includes use_unit("forms.inc.php"); use_unit("extctrls.inc.php"); use_unit("stdctrls.inc.php"); //Class definition class Page1 extends Page { public $Label8 = null; private $someVar; public function __construct($application) { parent::__construct($application); //load from storage $this->someVar = $_SESSION['someVar']; $this->Label8->Caption = $this->someVar; } public function __destruct() { //save to storage $_SESSION['someVar'] = $this->someVar;...
javascript,jquery,drupal-7,global
The solution was simply to put every single "script" in a seperate .js-file. If they were put into one .js-file, they would simply all become dysfunctional. Anyone knows whether this is a Drupal-specific strategy, or whether this is general to Javascript and known to everyone in "the field"?...
python,class,share,instance,global
* Main module ***************** import matplotlib as plt import plotter import shapes def main(): global thePlot thePlot = plotter.plotter() cyl = shapes.cylinder(r, c, n, color) cyl.draw() plt.show() And this: global thePlot * This line causes the error thePlot.plot(self.x, self.y, self.z, self.color) Should become: main.thePlot.plot(self.x, self.y, self.z, self.color) With the condition...
The problem is in your last four lines of code -- frame.start() doesn't quit until your game is finished, but you have new_game() after that, so the globals are never initialized.
javascript,variables,find,global,assign
You want to modify window[i] (the value of variable i), not i (the variable name). So you can do something like this: for (var i in window) { if (i.indexOf('variableName') == 0){ window[i] = true; } } ...
pthreads,global-variables,global,mutex,argv
You can use dynamic allocation, just like you would for any other type. The only difference here is that dynamically allocated mutexes must be initialised with pthread_mutex_init(): pthread_mutex_t *mutex; size_t n_mutex; int main (int argc, char **argv) { size_t i; if (argc < 2) return 1; n_mutex = atoi(argv[1]); if...
I recommend looking at this site. The way this example is set up, the tkinter app is a class. Your load_files() and run_process() functions will be functions of the class, and instead of using global variable (stay away from globals in python!), the variables will be class properties. Unfortunately this...
javascript,variables,backbone.js,global
I want to mention that Global variables are bad. Try to limit yourself to as few of them as possible. Global namespace pollution is very dangerous and can cause unexpected errors in the future. A technique I often use to get around the issue of polluting the global namespace is...
Because it may depend on the Python implementation how much work it is to build that dictionary. In CPython, globals are kept in just another mapping, and calling the globals() function returns a reference to that mapping. But other Python implementations are free to create a separate dictionary for the...
python,iphone,user-interface,uibutton,global
By default, when you assign to an identifier for the first time in a function it creates a local variable, even if there's a global one with the same name. Try this: def restart_time(sender): global start start = int(time()) button2 = str("Stopwatch restarted.") sender.title = None sender.title = str(button2) From...
Ciro's solution would have worked if I am only using func1 once; however func1 is called recursively so variable a cannot be global in file1 (i.e. the variable has to live on the stack and not on the heap). Here's the solution I ended up using: File1.c: #include <something.h> extern...
I've resolved my problem. I am not sure what I was doing wrong but now it works. For everyone who will have similar problem, don't forget to inject your values or constans to factory.
types,macros,global,local,stata
If you add =, then Stata will evaluate the expression that defines local date: clear set more off set obs 10 gen y_passed = _n local date = substr("$S_DATE",8,.) display `date' gen start_year = `date' - y_passed list Otherwise, the local just holds a string, but not a number in...
In the start method, you're referring to a variable called eth_addr, which isn't defined anywhere. It's also exactly what your error message is telling you. (you're probably looking for self.eth_addr) (in addition, stop using start_new_thread -- it's a low-level primitive that should never be called directly. Use threading.Thread objects instead.)...
Unless you declare the function as private, which limits the visibility to the file where it is defined, you can use it anywhere in the module if declared as internal (the default), and also from external modules if declared as public. However since you say that you need it in...
java,android,android-fragments,global
You could just pass the fragment manager into the method: public static void generateFragment(FragmentManager fragmentManager, String speechString, String buttonString) I would avoid having a BaseActivity as others have suggested, because it limits you to what you can extend from: e.g. FragmentActivity, ActionBarActivity, ListActivity, PreferenceActivity, e.t.c. Google "composition over inheritance" to...
javascript,jquery,ajax,variables,global
In JavaScript, a variable which has been declared without var keyword inside a function becomes global only after function's call. Consider this: function foo(){ bar = 123; } // Reference error - bar is undefined console.log(bar); Now before testing bar variable, let's call the foo function. function foo(){ bar =...
python,variables,if-statement,global,scoping
Has nothing to do with scope. The heaps don't grow because you pop newly added elements right off at the end: return (heapq.heappop(leftHeap) + curMedian)/2 else: return (heapq.heappop(rightHeap) + curMedian)/2 Just look at the max/min element without popping it off: return (leftHeap[0] + curMedian)/2 else: return (rightHeap[0] + curMedian)/2 My...
python,url,import,global,local
Also a thing to consider: Perhaps, just return a module and use it where needed? # hello.py def world(): print 'hello world!' # smuggle.py def smuggle(url, name): code = urllib.urlopen(url).read() module = imp.new_module(name) exec code in module.__dict__ return module hello = smuggle("http://127.0.0.1:1234/hello.py", "hello") hello.world() # prints out "hello world!" You...
ruby-on-rails,ruby,search,global
I think the best way in your case is to use ElasticSearch. A neat integration gem is provided here. Links to documentation are provided on that page.