Hi all,
I have the following simple script.
<script>
SPC = {
a : [10],
b : 10,
t: function()
{
y = this.a;
z = this.b;
y[0]++;
z++;
alert('this.a[0] = ' + this.a[0] + '\nthis.b = ' + this.b)
}
}
SPC.t();
SPC.t();
</script>
Running it in your browser will display two alert ...
Is it possible to include one function inside another? To learn functions, I'm trying to create a combat sequence using PHP. The sequence would look like this:
Dice would roll, assigning numbers to variables;
Hero1 attack results are printed;
Dice would roll, assigning numbers to variables;
Hereo2 attack results are printed;
Dice woul...
I have the following JavaScript (I'm using jQuery):
function language(language)
{
var text = new Object();
$.ajax({
type: "GET",
url: "includes/xml/languages/" + language + ".xml",
dataType: "xml",
success: function(xml){
$(xml).find('text').each(function(){
text[$(this).attr('id')] = $(this).te...
I'm getting an error in .net when trying to declare a Public class on my code behind page.
Partial Class _Default
Inherits System.Web.UI.Page
Public someVariable as integer
Public someClass as className
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load [...]
The error I'm ge...
Is there any way to keep global variables visible only from inside a library while inaccessible from programs that access that library in C?
It's not that it is vital to keep the variable protected, but I would rather it if programs couldn't import it as it is nothing of their business.
I don't care about solutions involving macros.
...
Hello everyone.
Following is a part of my code for a project:
public class Body extends Point{
public double x, y, mass;
public Body() {
x = y = mass = 0;
}
public Body(double x, double y, double mass) {
this.mass = mass;
this.x = x;
this.y = y;
}
}
public class Point {
public double x;
...
Hi,
I often have methods which are called regularly and have some "state" which has to be preserved between calls, as in:
float lastTime = 0.0f;
void Draw( float currentTime )
{
if( currentTime - lastTime > 0.5f )
{
// not enough FPS
}
lastTime = currentTime;
}
And it drives me nuts that the global "state" f...
Is it possible to declare a variable in c++ without instantiating it? I want to do something like this:
Animal a;
if( happyDay() )
a( "puppies" ); //constructor call
else
a( "toads" );
Basially, I just want to declare a outside of the conditional so it gets the right scope.
Is there any way to do this without using pointers ...
I know what my is in Perl. It defines a variable that exists only in the scope of the block in which it is defined. What does our do? How does it differ from my?
...
My problem is that I have to set a variable in a try statement otherwise I get a compile error.
Later on I need to use that variable but it is now out of scope, or so I believe. I initialise the variable outside the try statement and set it to null, I thought that it might then be accessible outside, but I still get a NullPointerExcepti...
I can understand why you would need a class variable to keep track of things like the total number of objects that have been instantiated in that class.
And I can understand why you would need an instance variable to store attributes of a particular object in that class.
But class instance variables I just can't seem to justify.
As I ...
I am using some third party library to connect to a server via async protocol and get response back. For example method to get userid by username looks like this:
public int getUserid(String username) {
int userid = 0;
connection.call("getUserid", new Responder() {
public void onResult(final int result) {
System.out.println(...
I'm having terrible trouble trying to understand python scoping rules.
With the following script:
a = 7
def printA():
print "Value of a is %d" % (a)
def setA(value):
a = value
print "Inside setA, a is now %d" %(a)
print "Before setA"
printA()
setA(42)
print "After setA"
printA()
Gives the unexpected (to me) output of:...
Hi,
In response to another question I asked about regular expressions, I was told to use the *preg_replace_callback* function (http://stackoverflow.com/questions/959017/) as a solution to my problem. This works great, but now I have a question relating to variable scope in callback functions.
The function that parses the text is part o...
We have a very large JavaScript application where after many months of coding there have inevitably sprung a couple scope slip ups where a variable is defined in the following fashion:
function() {
x = 5; ...
}
instead of:
function() {
var x = 5; ...
}
This is happening somewhere -- We're not sure where -- and s...
I'm lead dev for Bitfighter, and we're using Lua as a scripting language to allow players to program their own custom robot ships.
In Lua, you need not declare variables, and all variables default to global scope, unless declared otherwise. This leads to some problems. Take the following snippet, for example:
loc = bot:getLoc()
item...
Hi, I'm sure there's a simple answer for this; I just can't seem to find it. I made a nested function in Ruby, and I was having trouble accessing variables from the outer function inside the inner function:
def foo(x)
def bar
puts x
end
bar
42
end
foo(5)
I get: NameError: undefined local variable or method x' for main:Obj...
I'm looking at some older Perl code on Perl Monks to figure out programming with Win32::OLE and MS Word. Scattered throughout the code are variables with names like $MS::Word and the like, without a 'my' included in their declaration. After reading a bit on Google, I understand that these are called 'package variables' versus 'lexical va...
I have a hidden input element that I am using as a counter to use to name more input elements generated by JavaScript. To get the value of the counter i use
parseInt($('#counter').val());
However I use this code snippet several times in my code, so I thought it would be good to put it in a function
function getCounter(){
parseInt...
Can anyone explain how variable scoping works within a POE session? What is the proper way to pass state within the session, without impacting other sessions?
Thanks
Josh
...