scope

Javascript Closure -Local variable nested function [duplicate]

旧巷老猫 提交于 2019-12-13 07:37:15
问题 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 . I am trying to use a variable x defined inside a function P whose value I am trying to set in another function. It always comes undefined. I tried applying my mind to use closure but it's just going off my head. It does not gives me a string rather a object. The logic is as follows. function P(i){ var x; if(i!=null){ /

Running a real-time clock with AJAX

泄露秘密 提交于 2019-12-13 07:26:04
问题 Now that I was helped getting AJAX running just great, I'm having problems running a clock function with it.... Clock code (located in the head): <script type="text/javascript"> var ampm = "AM"; //Default var message=""; function startTime() { var today = new Date(); //Number goes here var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); h=checkTime2(h); document.getElementById('clocktxt').innerHTML=h+

Why can't update access an objects img properties?

≡放荡痞女 提交于 2019-12-13 07:20:23
问题 I'm trying to create a simple JS game engine on my own. Here's the code for one of the states. var menuState = { //state variables menuBttn: {x: _canvas.width/2, y:_canvas.height/2, img: imageArray[2], over: false, click: function(){changeState(2);}}, preload: function () { }, update: function(){ surface.clearRect(0, 0, _canvas.width, _canvas.height); for (var i = 0; i < menuAssets; i++){ surface.drawImage(menuState.menuBttn.img , menuState.menuBttn.x, menuState.menuBttn.y); console.log

Angular - Use form post values in controller

会有一股神秘感。 提交于 2019-12-13 07:05:10
问题 I'm writing my first application in AngularJS, and I'm new to javascript. I have a simple question: How do I use POST values from an html form in an angular controller? I have a form (i've stripped out the css and validation stuff for ease of reading): <form name="signupForm" novalidate> <input type="text" placeholder="Name..." ng-model="name" name="name" required /> <input type="email" name="email" ng-model="email" placeholder="Email..." required> <input type="password" placeholder="Password

Java scope of a variable

夙愿已清 提交于 2019-12-13 06:58:48
问题 I do not understand why the output of this code is 10 : package uno; public class A { int x = 10; A(){int x = 12; new B();} public static void main(String args[]){ int x = 11; new A(); } class B{ B(){System.out.println(x);} } } How does the scope in this example work? Why System.out.println(x); prints 10? Is it because the instruction System.out.println(x); is outside the parentesis of the costructor: A(){int x=12; new B();} and so int x = 12 lives only there but when System.out.println(x);

Use parameter in callbacks from function which called it

隐身守侯 提交于 2019-12-13 06:15:21
问题 if i call a function A passing a parameter param, in which an asynchronous function B is called, will the callback C of the asynchronous function B be able to use the parameter param given to function A ? if yes, will this change if in the time between the function B start and the callback C is invoked i re-invoke function A? Example: function A(param) { value1 = param; doc = "hello"; //this is the async function B; database.insert(doc, function() { //this is the invoked callback C when the

Create a reusable template for tabs in Meteor

柔情痞子 提交于 2019-12-13 06:07:18
问题 So I have a template like this <template name="tabs"> <ul class='tabs'> <li activetab='tab1'>stream</li> <li activetab='tab2'>projects</li> </ul> <div> {{#if activeTabIs "tab1"}} {{> tabBody1}} {{/if}} {{#if activeTabIs "tab2"}} {{> tabBody2}} {{/if}} </div> </template> with Template.tabs.events({ 'click .tabs li' : function (event, template) { Session.set("activeTab", $(event.currentTarget).attr("activetab")); } }); and Template.tabs.activeTabIs = function(tab) { return Session.get(

Python: Access from within a lambda a name that's in the scope but not in the namespace

那年仲夏 提交于 2019-12-13 05:43:16
问题 Consider the following code: aDict = {} execfile('file.py',globals(),aDict) aDict['func2']() # this calls func2 which in turn calls func1. But it fails And file.py contains this: def func1(): return 1 myVar = func1() # checking that func1 exists in the scope func2 = lambda: func1() This gives an error saying " NameError: global name 'func1' is not defined ." I'm not sure what is happening here. The code in file.py is executed with an empty local namespace. Then, inside that code, a new

PHP: how to get variable from function in another function? [duplicate]

天大地大妈咪最大 提交于 2019-12-13 05:20:25
问题 This question already has answers here : Accessing a variable defined in a parent function (5 answers) Closed 6 years ago . Example function a(){ $num = 1; function b(){ echo $num; // how to get $num value? } } In this case global not working, because $num isn't global variable. 回答1: function a() { $num = 1; function b($num) { echo $num; }; b($num); } a(); 回答2: You could use the S_SESSION to get the variable? function a(){ $_SESSION['num'] = 1; function b(){ echo $_SESSION['num']; } } Not

angular doesn't apply changes to array(remove item on socket event)

你。 提交于 2019-12-13 05:16:15
问题 First of all, sorry for my english, i'm ukrainian When socketio card delete event performed, there is nothing changed in view ng-repeat in my view <card object="item" ng-repeat="item in LOG"></card> In my controller $scope.LOG = [{...},...{...}]; SocketIO emit socket.on('card_was_deleted', function (data) { $scope.open_object = undefined; $scope.LOG = $scope.LOG.filter(function (obj) { return obj.ID != data.id; }); });//or var index = ...;$scope.LOG.splice(index, 1); I was looking for $scope.