scope

Within the same function, is it UB to access—through indirection—a local variable not in scope?

主宰稳场 提交于 2019-12-12 15:15:48
问题 After the second closing brace, b is accessible only through indirection through a . int main() { int *a; { int b = 42; a = &b; } printf("%d", *a); // UB? return 0; } Since b is not anymore in scope, is this UB? I know it's UB to dereference a pointer to a non-static local variable from a function that has already returned, but in this case everything is within the same function. This is UB in C++, but I'm not sure about C. 回答1: Yes, it's undefined behaviour to access any variable that has

UI-Router : Can I get always the same controller?

梦想的初衷 提交于 2019-12-12 15:15:09
问题 I'm using UI-Router to have some "menus" in my application. $stateProvider.state("list" url: "/Focales" templateUrl: "/demo/focals.html" controller: FocalCtrl) $stateProvider.state("collection" url: "/Collections" templateUrl: "/demo/collections.html" controller: CollectionCtrl) In my CollectionCtrl, I trigger a processing done on server and just waiting to display the information like this (CoffeeScript) Progress = $resource('/collections/getProgress') $scope.getProgress = () -> prg =

Variable Scope and Var

自作多情 提交于 2019-12-12 15:09:16
问题 It all started with these simple lines of code: a = 3; b = 2; function line(x) { var a = 5; var b = 4; return a*x+b; } // returns 17 b = line(a) - b; alert(b); // returns 36 c = line(a) + b; alert(c); Both alerts return 17 and 36, respectively. The control works as expected. Until… I make the mistake of changing the inside of the function like so: function line(x) { var a = 5; b = 4; return a*x+b; } Suddenly line 13 returns 15, line 17 returns 23 and the situation continues to deteriorate as

What's the global object within a module in nodejs?

喜你入骨 提交于 2019-12-12 14:43:02
问题 I know in node, every module gets an local scope and variable defined within one module won't escape to the global unless explicitly exported. What I want to know is when I declare a variable in one module file as the following, what's the global object this variable defined on? var obj = {}; // In browser, this is defined on window.obj // How about in the node? There is one statement that global is the object used as the local global scope, however the following test code fails: a = 1

QML scope: property binding in child object failing

落花浮王杯 提交于 2019-12-12 14:41:58
问题 I'm new to QML and ran into a scope problem while going a button tutorial. I solved it but I don't understand why the code didn't work in the first place: Problem The following code gives Runtime reference errors when the button is hovered over: main_broken.qml import QtQuick 2.0 import QtQuick.Controls 1.1 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Button Tester") Rectangle { id: simpleButton height: 75 width: 150 property color buttonColor: "light blue" property

jQuery: $.ajax success callback doesn't let me assign to outside private variable [duplicate]

≡放荡痞女 提交于 2019-12-12 13:28:37
问题 This question already has answers here : How do I return the response from an asynchronous call? (36 answers) Closed 4 years ago . var doCheck = function() { var data; $.ajax({ url: 'check.php', data: 'ch=check', success: function(resp) { data = resp; } }); console.log(data); return data == 1; }; The above code, regardless of the data only ever returns a 0 or a 1 . Within the scope of the success callback, this is true. The argument resp has a value of 0 or 1 depending on input . However,

Javascript closure / variable scope question - I know it works, but why?

半城伤御伤魂 提交于 2019-12-12 13:15:38
问题 I've been developing with JS for a while, and while I know that code below works, I don't really understand why it works. The way I see it, I've defined testString in testClosure function, and I'm expecting that variable to 'go away' when testClosure function is done, since it's local variable. However, when I call inner function with a timer, it's still aware of testString variable. Why? Isn't that variable gone five seconds ago when testClosure finished executing? Does the inner function

JavaScript/jQuery Variable Scope Issue with Nested .ajax() calls

大兔子大兔子 提交于 2019-12-12 12:34:44
问题 I'm having a difficult time passing the variable postData which is a serialized jQuery array object to a nested child .ajax() call. postData is passed successfully to the first .ajax() call, but when I attempt to use it in the second .ajax() call, it does not post any form elements, as the variable is undefined at that level: $(".myForm").submit(function () { var postData=$(this).serializeArray(); $.ajax({ type : "POST", async : false, cache : false, url : "./insertComment.php", data :

WPF user controls and name scoping

送分小仙女□ 提交于 2019-12-12 11:21:53
问题 I've been playing around with WPF and MVVM and noticed a strange thing. When using {Binding ElementName=...} on a custom user control, the name of the root element within the user control seems to be visible in the window using the control. Say, here is an example user control: <UserControl x:Class="TryWPF.EmployeeControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TryWPF" Name="root">

Does Node.js support let keyword? [duplicate]

时间秒杀一切 提交于 2019-12-12 11:16:10
问题 This question already has answers here : Does node.js support the 'let' statement? (5 answers) Closed 6 years ago . In Javascript 1.7 the let keyword introduces block scope. This is arguably the most needed feature of Javascript and I was wondering if Node.js supports it. Part of my difficult in ascertaining this is Node runs Google's V8 engine, which comes from such and such standard and I don't know how these line up with the Javascript x.y version numbers. 回答1: Yes, the let keyword is