scope

variable no accessible after a Firebase call [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-12 02:55:17
问题 This question already has answers here : Passing variable in parent scope to callback function (3 answers) Closed 4 years ago . I'm using Firebase to access to same data, but i can't use the data out of the function used to access it. How i can make a console log of the data just accessed instead of the initial value? var whatNeed = 'hello'; gameData = new Firebase('https://thegame.firebaseio.com/gameData'); gameData.on("value", function(snapshot) { var data = snapshot.val(); whatNeed = data

replacing eval in privately scoped variables

大城市里の小女人 提交于 2019-12-12 02:54:59
问题 I'm trying to remove the eval statement in this function. I'm used to the this[whatever] style replacement but it doesn't work out in this instance. Have a look: var App = (function(fw) { var somevar1 = "hello"; var somevar2 = "world"; this.get = function(what) { return eval(what); } }); var app = new App({some: "thing"}); // now for the use: console.log(app.get("somevar1"),app);​ In the function, all my normal "eval scrubbing" options are not working for instance, I cant use: return this

Setting up a db connection using variables from another file

旧巷老猫 提交于 2019-12-12 02:52:07
问题 I am attempting to set up a db connection for a mysqli_connect statement $dbc. I had it working in my script with the following: DEFINE ('DB_USER','myName'; DEFINE ('DB_PASSWORD','somePass123'; DEFINE ('DB_HOST','localhost'; DEFINE ('DB_NAME','sitename'; // make the db connection $dbc = @mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) OR die ('Could not connect to mysql: ' . mysqli_connect_error()); I then posted a question on SO about security and best practice and was advised that if

What is the shortest possible way to write a block scope in JavaScript?

守給你的承諾、 提交于 2019-12-12 02:49:38
问题 Is this the shortest possible way to get a block scope in the body of the for loop? x = {}; for (i of ['a', 'b']) { (function(i) { x[i] = function() { this.v = i; } })(i); } Or is there any syntactic sugar I am not able to find? Explanation: With block scope the created objects have different values. new x.a ⟹ x.(anonymous function) {v: "a"} new x.b ⟹ x.(anonymous function) {v: "b"} Without block scope y = {}; for (i of ['a', 'b']) { y[i] = function() { this.v = i; } } the created objects

How do I access previous promise results in a .then() chain?

浪子不回头ぞ 提交于 2019-12-12 02:49:14
问题 I have restructured my code to promises, and built a wonderful long flat promise chain , consisting of multiple .then() callbacks. In the end I want to return some composite value, and need to access multiple intermediate promise results . However the resolution values from the middle of the sequence are not in scope in the last callback, how do I access them? function getExample() { return promiseA(…).then(function(resultA) { // Some processing return promiseB(…); }).then(function(resultB) {

What is the recommended naming for scoped units in Delphi XE2 onwards?

ⅰ亾dé卋堺 提交于 2019-12-12 02:43:22
问题 With the advent of Delphi XE2 scoped units like Xml.Internal.AdomCore_4_3 or System.StrUtils came in fashion. I like the ability to use such descriptive names but I am puzzled what are the naming conventions and preffered directory structure. Should it be com.company.project.Security.Compression.ZLib.pas like in Java System.Security.Compression.ZLib.pas like in .NET or something else? Should I place my files in a directory strcuture like this System\Security\Compression\System.Security

keeping track of multiple runs of the same function, part 2

╄→гoц情女王★ 提交于 2019-12-12 02:34:39
问题 This is related to this Anyway what I need is actually something slightly different I need some way of doing this: function run(arg) { this.ran = this.ran || false; if (!this.ran) init; /* code */ this.ran = true; } This works fine, I just want to make sure that this code works even when this in case it was called with call() or apply() Check this out for what I'm talking about, All of the calls after the first one should all be true, no matter the context 回答1: to get full use of closures, i

Rails 3 Possible ERB Bug When Executing Raw SQL/Calling Scopes?

烈酒焚心 提交于 2019-12-12 02:30:26
问题 in my User model I have a scope: scope :with_tournament_entrees, :include => :registers, :conditions => "registers.id IS NOT NULL" I wanted to see the SQL being generated by this scope and it produces: "SELECT \"users\".* FROM \"users\" WHERE (registers.id IS NOT NULL)" I don't see any mention of the include parameter I added and returns an error if executed in the console as raw SQL with the help of ActiveRecord::Base.connection.execute . If I was to query User.with_tournament_entrees in the

unique random id

穿精又带淫゛_ 提交于 2019-12-12 02:25:11
问题 I am generating unique id for my small application but I am facing some variable scope problem. my code- function create_id() { global $myusername; $part1 = substr($myusername, 0, -4); $part2 = rand (99,99999); $part3 = date("s"); return $part1.$part2.$part3; } $id; $count=0; while($count == 1) { $id; $id=create_id(); $sqlcheck = "Select * FROM ruser WHERE userId='$id';"; $count =mysql_query($sqlcheck,$link)or die(mysql_error()); } echo $id; I dont know which variable I have to declare as

update/refresh angularjs ng-repeat with data from server

北战南征 提交于 2019-12-12 02:23:34
问题 I try to buil a website to like some pictures. I can load the picture, but I want to have a like system with who like the picture. my problem was I have to refresh the page to see who like this picture and increment the count. this my controller : $scope.loadingpics = function (){ $http.get('/api/photos') .success(function(awesomeThings) { console.log(awesomeThings); $scope.firstname = awesomeThings; }) .error(function (err){ $scope.errors.other = err.message; }); }; $scope.upVote = function