我正在努力使用Javascript 经典继承 1.虽然道格拉斯·克罗克福德最终拒绝在Javascript中支持经典模型,但我觉得有趣的是:
我已经写了8年的JavaScript了,我从来没有发现需要使用超级函数.超级想法在经典模式中相当重要,但在原型和功能模式中似乎是不必要的.我现在看到我早期尝试在JavaScript中支持经典模型是一个错误.
然而,对于寄生遗传的问题,有一些不太明确的事情:
function ZParenizor2(value) {
var that = new Parenizor(value);
that.toString = function () {
if (this.getValue()) {
return this.uber('toString');
}
return "-0-"
};
return that;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,ZParenizor是根据Parenizor定义的.但Parenizor是基类,它继承自无人.所以this.uber函数不会被定义,实际上我在调用toString新的ZParenizor2对象的方法时会出错.
我是正确的,还是我无视某些事情?
更新
我是对的.此方法仅在您创建ZParenizor时使用0作为参数,因为它不需要调用该uber方法(正如您可以从方法imeplementation中看到的那样).
当您使用不同的参数尝试它时,我收到此错误:
Uncaught TypeError: Object #<error> has no method 'uber'
Run Code Online (Sandbox Code Playgroud) 有没有一种聪明的方法来迭代Python中的两个列表(不使用列表推导)?
我的意思是,像这样:
# (a, b) is the cartesian product between the two lists' elements
for a, b in list1, list2:
foo(a, b)
Run Code Online (Sandbox Code Playgroud)
代替:
for a in list1:
for b in list2:
foo(a, b)
Run Code Online (Sandbox Code Playgroud) 我有以下问题.我需要在字符串中找到动词JavaScript.我想知道,如果有类似(JAWS)的东西,Java API Wordnet,但是对于JavaScript.
更具体地说,我正在寻找某种能够在文本或网页中返回动词列表的RESTful Web服务.
如果您知道有用的内容,请不要犹豫,发布您的答案.
我正在开发Chrome扩展程序,我遇到了以下问题.当某个事件发生时,我的后台页面会创建一个带有chrome.tabs.createAPI 的新选项卡(页面)并发送一个Object.
发送的Object(称为items)是一个对象列表,具有一个名为Item的特定类(原型).
这里有一些代码:
// in background.html
chrome.tabs.create({index: 0, url: "results.html"}, function(tab) {
chrome.tabs.sendRequest(tab.id, {'items': itemsList}, function(response) {
console.log(response.farewall);
});
});
Run Code Online (Sandbox Code Playgroud)
另一方面,在新创建的页面中,我收到发送的对象
// newpage.html
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.dir(request.items);
sendResponse({});
}
);
Run Code Online (Sandbox Code Playgroud)
问题是,当我收到对象列表时,newpage.html对象类型丢失了.确实console.dir()在新的中使用了background page,itemsList中的对象类型被正确报告,但是没有在收到的项目列表对象中报告newpage.html.
我可以手动background.html通过字符串手动序列化数据,并手动反序列化newpage.html但我想知道是否有更好的方法来支付这一点并防止列表中的对象类型(即Item)丢失.
是否可以同时迭代多个文件的行?我需要通过连接两个不同文件中的行来输出文件(并添加一些额外的单词).
我知道CMD命令:
FOR %variable IN (set) DO command [command-parameters]
Run Code Online (Sandbox Code Playgroud)
但是,如果您需要同时迭代两个文件,这无济于事.更准确地说,我需要以下内容:
While the first file is not ended
line1 <- READ a line from the first file
line2 <- READ a line from the second file
WRITE on a third file line1 + line2
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来完成我之前在dos批处理文件中描述的内容.谢谢!
可以访问功能的进一步范围吗?我会更好地解释.
我有一个函数,我想从中调用它的调用函数作用域.
function called() {
// i want to access the calling outer function scope
}
function calling() {
called();
}
Run Code Online (Sandbox Code Playgroud)
obviusly called()函数可以被很多calling函数调用,并且called()必须知道哪个函数调用了他,`并访问它的作用域变量和函数.
如何在文件中获取与给定匹配的所有文本片段的行号regexp?
file_content = f.read()
m = re.compile('regexp')
# How to extract line numbers of the matched text snippets?
Run Code Online (Sandbox Code Playgroud)
正则表达式不能跨越行。
python中是否有一个快捷方式,用于将相同的函数multiple times应用于变量(及其输出)?
就像是:
# n times foo(x)
Run Code Online (Sandbox Code Playgroud)
代替
foo(foo(foo...(foo(x))))...)
Run Code Online (Sandbox Code Playgroud) javascript ×4
python ×3
function ×2
batch-file ×1
cmd ×1
file ×1
inheritance ×1
iteration ×1
list ×1
nlp ×1
regex ×1
scope ×1