scope

Inheriting aliases inside UNIX /usr/bin/script

喜夏-厌秋 提交于 2020-01-14 13:50:46
问题 The UNIX "/usr/bin/script" command will create a running transcript of your shell session (see "man script" for more info). However, when inside a script instance, it seems to forget the parent shell's env vars, aliases, etc. The following example demonstrates how the "ll" alias I define is ignored inside "script": zsh> mkdir temp zsh> cd temp zsh> alias "ll=ls -alF" zsh> ll total 24 drwxr-xr-x 2 me mygroup 4096 Feb 18 13:32 ./ drwxr-xr-x 28 me mygroup 8192 Feb 18 13:32 ../ zsh> script a.out

Inheriting aliases inside UNIX /usr/bin/script

只愿长相守 提交于 2020-01-14 13:49:24
问题 The UNIX "/usr/bin/script" command will create a running transcript of your shell session (see "man script" for more info). However, when inside a script instance, it seems to forget the parent shell's env vars, aliases, etc. The following example demonstrates how the "ll" alias I define is ignored inside "script": zsh> mkdir temp zsh> cd temp zsh> alias "ll=ls -alF" zsh> ll total 24 drwxr-xr-x 2 me mygroup 4096 Feb 18 13:32 ./ drwxr-xr-x 28 me mygroup 8192 Feb 18 13:32 ../ zsh> script a.out

Is this a variable scoping bug in NodeJS or do I just need more sleep

♀尐吖头ヾ 提交于 2020-01-14 11:38:25
问题 Working on a NodeJS project, I came a across this very unexpected behaviour that I can't figure a way around - it seems like a bug to me, but perhaps I'm simply misunderstanding how NodeJS modules operate. I've reduced it into a testcase as follows: mod.js module exports.process = function(obj) { obj.two = 'two'; }; test.js file var testObj = {one: 'one'}; console.log(['Before:', testObj]); var cachedObj = testObj; require('./mod').process(cachedObj); console.log(['After:', testObj]); Then

Is this a variable scoping bug in NodeJS or do I just need more sleep

喜欢而已 提交于 2020-01-14 11:36:07
问题 Working on a NodeJS project, I came a across this very unexpected behaviour that I can't figure a way around - it seems like a bug to me, but perhaps I'm simply misunderstanding how NodeJS modules operate. I've reduced it into a testcase as follows: mod.js module exports.process = function(obj) { obj.two = 'two'; }; test.js file var testObj = {one: 'one'}; console.log(['Before:', testObj]); var cachedObj = testObj; require('./mod').process(cachedObj); console.log(['After:', testObj]); Then

variable-scope in R functions

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 07:58:30
问题 I'd like to specify functions in a flexible way. How can I make sure that the environment of a given function does not change when I create another function just after it. To illustrate, this works properly: make.fn2 <- function(a, b) { fn2 <- function(x) { return( x + a + b ) } return( fn2 ) } a <- 2; b <- 3 fn2.1 <- make.fn2(a, b) fn2.1(3) # 8 fn2.1(4) # 9 a <- 4 fn2.2 <- make.fn2(a, b) fn2.2(3) # 10 fn2.1(3) # 8 This does not make.fn2 <- function(a, b) { fn2 <- function(x) { return( x + a

R environments and function call stacks

独自空忆成欢 提交于 2020-01-14 07:58:07
问题 I am trying to use get in series of function calls, but the lookup of the object names seems to skip environments. For example: foo <- 1 # variable in .GlobalEnv getter <- function(x) {get(x)} getter("foo") # returns 1, which is expected f1 <- function() { foo <- 2 # local variable in the function scope getter("foo") } f1() # still returns 1, would've expected to return 2 Why is it that calling f1 returns the foo in the global environment and not the foo in the calling function's environment?

Scope of System.setProperty in Tomcat

耗尽温柔 提交于 2020-01-14 07:37:08
问题 This question is "cousin" of this one involving Android. But here we are in Tomcat environment . If in my webapp I set a property with System.setProperty("property_name", "property_value"); , which scope will it be applied to? all JVM in this machine all Tomcat webapps only the webapp that executes the instruction only the thread that executes the instruction something else... Many thanks! 回答1: A system property has a JVM scope. The property will thus be modified (and available) in the whole

Scope of System.setProperty in Tomcat

独自空忆成欢 提交于 2020-01-14 07:37:08
问题 This question is "cousin" of this one involving Android. But here we are in Tomcat environment . If in my webapp I set a property with System.setProperty("property_name", "property_value"); , which scope will it be applied to? all JVM in this machine all Tomcat webapps only the webapp that executes the instruction only the thread that executes the instruction something else... Many thanks! 回答1: A system property has a JVM scope. The property will thus be modified (and available) in the whole

Retrieving value from javascript callback function

这一生的挚爱 提交于 2020-01-14 05:00:09
问题 var display_welcome = function(){ var fb_login_button = jQuery('#fb_login_button'); var fb_welcome = jQuery('#fb_welcome'); var name = ''; FB.api('/me',function(response){ console.log(response); name = response.first_name; }); fb_login_button.css('display', 'none'); fb_welcome.html('<span>Welcome, ' + name + '</span>'); fb_welcome.css('display', 'block'); }; This function is called when a user logs into Facebook from a website. The goal is to display a welcome message to the user with the

Global variables scope in modules

拜拜、爱过 提交于 2020-01-14 03:01:07
问题 Following are my files and output. All I want to do is get Value of x after func1() as 20 . I have already referred to this answer. I want to know why this do not work? Is it necessary to use import globalVar instead of from globalVar import * globalVar.py #globalVar.py x=10 fun1.py from globalVar import * def func1(): global x x=20 print("X in fun1",x) main.py from fun1 import * from globalVar import * print("X before fun1=",x) func1() print("X after fun1=",x) Output: X before fun1= 10 X in