我有一个我需要从node.js脚本的脚本,我想保持javascript引擎独立.
所以,例如,我想做:
__PRE__
只有它在node.js下运行 我该怎么办这个测试?
编辑:发布此问题时,我不知道node.js模块功能是基于commonjs.
对于具体的例子,我提出了一个更准确的问题:
脚本如何判断它是否需要作为commonjs模块?
请帮我理解这个:
在v1.6.6上,它位于第2744行google/appengine/ext/db/__init__.py:
class UnindexedProperty(Property):
"""A property that isn't indexed by either built-in or composite indices.
TextProperty and BlobProperty derive from this class.
"""
def __init__(self, *args, **kwds):
"""Construct property. See the Property class for details.
Raises:
ConfigurationError if indexed=True.
"""
self._require_parameter(kwds, 'indexed', False)
kwds['indexed'] = True
super(UnindexedProperty, self).__init__(*args, **kwds)
.
.
.
Run Code Online (Sandbox Code Playgroud)
在他们将索引参数约束为False之后 - 将它们设置为True!
以下代码添加了对blobstore中的文件执行某些处理的任务,它在B2 后端上运行,因此它没有超时限制:
for task in tasks:
tools.debug("add_tasks_to_process_files", "adding_task")
taskqueue.add(\
name=("Process_%s_files---%s--%s--%s--%s" % \
(len(tasks[task]), task[1], task[0], task[2], int(time.time()))),\
queue_name="files-processor",\
url="/analytics/process_files/",\
params={"processing_task": json.dumps({"profile": task, "blobs_to_process": tasks[task]})})
Run Code Online (Sandbox Code Playgroud)
tasks是以下形式的字典:
{
(x1,y1,z1): ["blob_key", "blob_key"... (limited to 35 keys)],
(x2,y2,z2): ["blob_key", "blob_key"...],
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
x1,y1,z1都是字符串
tools.debug是我写的一个函数,它使用urlfetch将消息发送到我的本地服务器(因此我不必等待20分钟才能读取日志):
def debug(location, message, params=None, force=False):
if not (settings.REMOTE_DEBUG or settings.LOCALE_DEBUG or force):
return
if params is None:
params = {}
params["memory"] = runtime.memory_usage().current()
params["instance_id"] = settings.INSTANCE_ID
debug_message = "%s/%s?%s" % (urllib2.quote(location), urllib2.quote(message), "&".join(["%s=%s" % (p, urllib2.quote(unicode(params[p]).encode("utf-8"))) for …Run Code Online (Sandbox Code Playgroud) 说我有两个构造函数:
A = function () {
this.x = 'x';
};
A.prototype.a = 'a';
B = function () {
this.y = 'y';
};
B.prototype.b = 'b';
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建一个对象AB将从两者的原型继承?所以下面的例子将起作用:
ab.a === 'a'; // true
ab.b === 'b'; // true
A.prototype.a = 'm';
ab.a === 'm'; // true
B.prototype.b = 'n';
ab.b === 'n'; // true
Run Code Online (Sandbox Code Playgroud)
谢谢
我想循环以'.'开头的文件.在目录x中(x可能是任何路径):
$ for file in x/.*
> do
> echo -n $file" "
> done
x/. x/.. x/..a x/.b
Run Code Online (Sandbox Code Playgroud)
什么是摆脱x /.和x/..的最佳方法?
javascript ×2
python ×2
bash ×1
commonjs ×1
constructor ×1
glob ×1
inheritance ×1
memory-leaks ×1
node.js ×1
prototype ×1
shell ×1