Consider this code:
const char* someFun() {
// ... some stuff
return "Some text!!"
}
int main()
{
{ // Block: A
const char* retStr = someFun();
// use retStr
}
}
My question is in the function sumFun() where is "some Text!!", stored (i think may be in some static area in ROM) and what will be its scope?
Wi...
The jQuery.getJSON() method seems to ignore the normal rules of scoping within JavaScript.
Given code such as this...
someObject = {
someMethod: function(){
var foo;
$.getJSON('http://www.somewhere.com/some_resource', function(data){
foo = data.bar;
});
alert(foo); // undefined
}
}
...
When I call a function, a local scope is erected for that call. Is there any way to directly reference that scope as an object? Just like window is a reference for the global scope object.
Example:
function test(foo){
var bar=1
//Now, can I access the object containing foo, bar, arguments and anything
//else within the loca...
Hi
I'm having issues with the functions.php file with variables
$prev_dept = 0;
$comment_count = 0;
$comment_index = 0;
function setCommentCount($size){
$comment_count = $size;
}
function flowhub_comment($comment, $args, $depth) {
$comment_index ++; ...
Hi. I'm trying to iterate through all components and for those who implements ISupportsOpen allow to open a project.
The problem is when the anonymous method is called, then the component variable is always the same element (as coming from the outer scope from IEnumerable)
foreach (ISupportsOpen component in something.Site.Container.Com...
I ran into an interesting issue the other day and was wondering if someone could shed light on why this is happening. Here is what I am doing (for the purposes of this example I have dumbed down the example somewhat):
I am creating a globally scoped variable using the square bracket notation and assigning it a value.
Later I declare a ...
(creating a separate question after comments on this: http://stackoverflow.com/questions/2634410/javascript-redeclared-global-variable-overrides-old-value)
I am creating a globally scoped variable using the square bracket notation and assigning it a value inside an external js file.
In another js file I declare a var with the same name...
Hello.
I have the following code:
@implementation SendMapViewController
NSMutableArray *emails;
At this method I create emails array and I add some NSStrings:
- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson: (ABRecordRef)person {
ABMultiVal...
I have a code structure something like this:
For row = 1 To numRows
Dim arrayIndex As Integer = 0
For column As Integer = startColumn To endColumn
' whatever code
arrayIndex = arrayIndex + 1
Next
Next
Dim arrayIndex As Integer = 0
For column As Integer = startColumn To endColumn
' whatever code
arrayIndex = a...
Example:
// access fields directly
private void doThis()
{
return doSomeWork(this.data);
}
// receive data as an argument
private void doThis(data)
{
return doSomeWork(data);
}
The first option is coupled to the value in this.data while the second option avoids this coupling. I feel like the second option is always better. It...
$(".delete").click(
function() {
var thesender = this;
$(thesender).text("Del...");
$.getJSON("ajax.php", {},
function(data) {
if (data["result"])
$(thesender).remove(); // variable defined outside
else
alert('Error!');
...
I have a variable which holds a score for a game.
My variable is accessible and correct outside of an if statement but not inside as shown below
score is declared at the top of the main.cpp and calculated in the display function which also contains the code below
cout << score << endl; //works
if(!justFinished){
cout << sc...
I'm teaching my self python and I was translating some sample code into this
class Student(object):
def __init__( self, name, a,b,c ):
self.name = name
self.a = a
self.b = b
self.c = c
def average(self):
return ( a+b+c ) / 3.0
Which is pretty much my intended class definition
Later in...
So I'm playing around with JavaScript and came across what I think to be an oddity. Is anyone able to explain the following? (i've included the alerted values as comments)
Why is the first alert(msg) inside foo() returning undefined and not outside?
var msg = 'outside';
function foo() {
alert(msg); // undefined
var msg = 'inside'...
ok. I have a really odd and mind boggling problem. I have two class files, both of which are NSObject inheritors. The series of code is as follows
CustomClass *obj;
obj = [[CustomClass alloc] init];
[myArray addObject:obj]; <--------Immediately after this line if I hover over the array it shows it as having 1 object that is out of ...
I'm just starting out learning javascript, and tried to write a little script that would make a grid of divs on a page.
Here's the script:
var tileWidth=50;
var tileHeight=100;
var leftPos=10;
var topPos=10;
var columns=10;
var rows=10;
var spacing=5;
$('document').ready(function() {
placeTiles();
});
function makeRow() {
for (var ...
Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function.
I define a function:
void someFunction(double results[])
{
for (int i = 0; i<100; ++i)
{
for (int n = 0; n<16; +...
I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors.
Given this code:
#!/usr/bin/python
def test_function():
try:
a = str(5)
raise
b = str(6)
except:
...
I have a main function in A.cpp which has the following relevant two lines of code:
B definition(input_file);
definition.Print();
In B.h I have the following relevant lines of code:
class B
{
public:
// Constructors
B(void);
B(const char *filename);
~B(voi...
Can someone explain why the alert returns "undefined" instead of "hello"?
window.onload = function() {
var a = 'hello';
alert(window.a);
}
...