我有一个设置的变量.bashrc.
在~/.bashrc:
PROJ_HOME=~/Projects/stable
Run Code Online (Sandbox Code Playgroud)
从bash shell,我想做这样的事情:
$ su -l kenneth -c 'echo $PROJ_HOME'
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,预期/home/kenneth/Projects/stable不会打印出来.
有关如何做到这一点的任何想法?
我有两个模块:apirequest.js和feed.js. 当我打电话feed.start()的apirequest,我得到的,TypeError: Object #<Feed> has no method 'start'.为什么是这样?不util.inherits(Feed, APIRequest);继承APIRequest的属性?
apirequest.js
var EventEmitter = require('events').EventEmitter;
var util = require('util');
function APIRequest(endpoint) { }
APIRequest.prototype.start = function() { }
util.inherits(APIRequest, EventEmitter);
module.exports = APIRequest;
Run Code Online (Sandbox Code Playgroud)
feed.js
var util = require('util');
var APIRequest = require('../lib/api_request');
function Feed(endpoint) {
APIRequest.call(this, endpoint);
}
util.inherits(Feed, APIRequest);
var feed = new Feed(endpoint);
feed.start();
Run Code Online (Sandbox Code Playgroud) 为什么Chrome调试程序会跳过删除语句?如果在控制台中运行,以下代码将演示观察结果.
(function () {
var foo = { bar: true };
debugger;
delete foo.bar;
})();
Run Code Online (Sandbox Code Playgroud) 是否可以在同一程序中多次启动反应堆?假设您希望将扭曲的功能封装在方法中,以用于API目的.
例如,mymodule.py看起来像这样:
1 from twisted.web.client import getPage
2 from twisted.internet import reactor
3
4 def _result(r):
5 print r
6 reactor.stop()
7
8 def _error(e):
9 print e
10 reactor.stop()
11
12 def getGoogle():
13 d = getPage('http://www.google.com')
14 d.addCallbacks(_result, _error)
15 reactor.run()
16
17 def getYahoo():
18 d = getPage('http://www.yahoo.com')
19 d.addCallbacks(_result, _error)
20 reactor.run()
21
Run Code Online (Sandbox Code Playgroud)
main.py看起来像这样:
1 import mymodule
2
3 getGoogle()
4 getYahoo()
Run Code Online (Sandbox Code Playgroud) 出于调试目的,我发现如果我可以打印局部作用域中的变量并且只打印局部作用域中的变量,那将是有益的.
样品:
def showAuthUser(self):
"""Make a request to the campfire server.
Returns a getPage object which is deferred.
"""
u = self.uri + self._resource['showAuthUser']
m = 'GET'
n = self.username
p = self.password
b = base64.encodestring('{0}:{1}'.format(n, p))
h = {'Authorization': 'Basic ' + b.strip()}
return self._getPage(u, m, h)
Run Code Online (Sandbox Code Playgroud)
有没有办法在h之后找到局部范围内的所有变量的值?
我有一个案例,我需要检查页面上是否存在jQuery,如果没有,我需要加载它.我创建一个脚本标记并引用外部jQuery库.在继续使用脚本的其余部分之前,如何等待在页面上加载库?
更新:
继祗园的建议后,看起来是什么样的:
if (typeof jQuery === 'undefined') {
var j = document.createElement('SCRIPT');
j.type = 'text/javascript';
j.src = '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(j);
j.onload = function () {
var section = document.createElement('DIV');
section.setAttribute('style', 'height:300px; width:250px; position: fixed; right: 0px; top: 100px;z-index: 9999; border-style:solid;border-width:1px;');
section.innerHTML = '<p>steps</p><textarea name="steps"></textarea><p>expected results</p><textarea name="results"></textarea><p><input type="button" name="submit" value="add test case" /></p>';
document.getElementsByTagName('body')[0].appendChild(section);
};
}
Run Code Online (Sandbox Code Playgroud)