scope

Sinatra Variable Scope

Deadly 提交于 2019-12-09 15:36:41
问题 Take the following code: ### Dependencies require 'rubygems' require 'sinatra' require 'datamapper' ### Configuration config = YAML::load(File.read('config.yml')) name = config['config']['name'] description = config['config']['description'] username = config['config']['username'] password = config['config']['password'] theme = config['config']['theme'] set :public, 'views/themes/#{theme}/static' ### Models DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/marvin.db") class Post include

Scope of System.setProperty

烈酒焚心 提交于 2019-12-09 15:05:08
问题 What's the scope of System.setProperty in Android? If I set a property (say System.setProperty("http.keepAlive", "false") ), does it affect all apps in the system, the current app, the current task or the current thread only? Where is this documented? 回答1: Java "system" properties do not cross process boundaries, they are held in memory and are tied to a single instance of the virtual machine. Therefore if you set a system property within application it will not be visible to other

Remove and restore Scope from digest cycles

浪尽此生 提交于 2019-12-09 14:43:33
问题 Is there a way to remove a scope from the digest cycles? In other words, to suspend/resume a scope digest cycle? In my case, I have all pages already loaded, but not all of them visible. So I'd like to suspend the ones that aren't visible to avoid useless processing. I don't want to use ng-view + $route , I don't want/need deep-linking. I saw this thread and arrived to this fiddle. It probably does the work, but it's pretty invasive and not very framework-update-friendly. Is there any other

Is there a way to set the scope of require_once() explicitly to global?

删除回忆录丶 提交于 2019-12-09 14:38:51
问题 I'm looking for a way to set the scope of require_once() to the global scope, when require_once() is used inside a function. Something like the following code should work: file `foo.php': <?php $foo = 42; actual code: <?php function includeFooFile() { require_once("foo.php"); // scope of "foo.php" will be the function scope } $foo = 23; includeFooFile(); echo($foo."\n"); // will print 23, but I want it to print 42. Is there a way to explicitly set the scope of require_once() ? Is there a nice

Scope in javascript acting weird

倖福魔咒の 提交于 2019-12-09 14:11:01
问题 Object are passed with their reference in javascript. Meaning change in that object from any where should be reflected. In this case, the expected output was {} for console.log(a) function change(a,b) { a.x = 'added'; a = b;//assigning a as {} to b } a={} b={} change(a,b); console.log(a); //expected {} but output {x:'added'} console.log(b) What is happening here? It should not be because of functional scope as far as I know. Thank you 回答1: If you added another line you can get a clearer

Variable hoisting - “var” with global variable name in function

别等时光非礼了梦想. 提交于 2019-12-09 14:05:29
问题 I was practicing some scenario and find a case: Here is fiddle According to closure bar function should have access to var x so I expected to alert 1 and condition get false due to if(!1) but it alerted undefined and condition get true and second alert is with value 10. var x = 1; function bar() { alert(x); if (!x) { var x = 10; } alert(x); } bar(); So I am confused why it is prompting undefined? According to hoisting in a particular scope you define a variable anywhere it is considered as

How do I edit a global variable in a JQuery $.each function?

泪湿孤枕 提交于 2019-12-09 13:46:10
问题 Ok, so that title probably doesn't explain my question well. Hopefully this makes sense. This is also my first application with jQuery, so forgive me if I'm doing something dumb. I have the following function: function getRandomImages(limit) { imagesArray = new Array(); $.getJSON('createImageArray.php', {limit: limit}, function(data) { $.each(data, function(i) { imagesArray[i] = data[i]; //imagesArray is declared globally. }); }); } The getJSON is correctly grabbing the JSON object. It

javascript setTimeout call error

ⅰ亾dé卋堺 提交于 2019-12-09 11:39:48
问题 I want to invoke the window.setTimeot function with my custom scope so I use the call method, but there is something wrong. function foo() { this.bar = function() { console.log("keep going"); window.setTimeout.call(this,this.bar,100); } this.bar(); } new foo; under Firefox this prints to the console only 1 line and then nothing, and under google chrome it throws a TypeError. What is the problem in my code? 回答1: Using call does not help here: it calls setTimeout with your this object, but the

Greasemonkey Script and Function Scope

一曲冷凌霜 提交于 2019-12-09 11:25:13
问题 Here is my script code: // ==UserScript== // @name test // @description test // @include http://* // @copyright Bruno Tyndall // ==/UserScript== var main = function() { var b = document.getElementsByTagName('body')[0]; var t = document.createElement('div'); t.innerHTML = '<a href="javascript:void(0);" style="color:white;">Hello World</a>'; t.style.position = 'absolute'; t.style.zIndex = 1000; t.style.bottom = '5px'; t.style.right = '5px'; t.firstChild.setAttribute('onclick', 'test();'); b

Expire specific managed bean instance after time interval

谁说我不能喝 提交于 2019-12-09 06:25:24
问题 I have 2 JSF managed beans A and B and I need to expire/destruct/destroy A after 2 minutes and B after 5 minutes. I checked this related question Timing out from a bean, but it is expiring whole session. I do not want to expire whole session. How can I achieve this with a custom scope? 回答1: Given that you're using JSF bean management facility (and thus not CDI, which would require a completely different answer), you can achieve this with @CustomScoped. The @CustomScoped value must refer a Map