1

我想我误解了一些范围界定问题。我正在运行 TODO 主干应用程序并在“new app.AppView();”之后

我正在尝试这个:app.AppView.render()

以及我认为正在扩展的其他功能,但它们似乎不可用。

第二个问题是..为什么chrome开发者工具在TODORouter和Todos旁边说“child”

编辑待办事项链接 TODO

这是我主要参考的代码

$(function() {

    // Kick things off by creating the **App**.
    new app.AppView();

});
4

2 回答 2

2

将新的 appview 保存在 var 中,然后从那里使用它。

var myAppView = new app.AppView();
// ...
myAppView.render();
于 2013-01-17T14:42:29.007 回答
1

You don't have scoping issues, but kind of 'coping with javascript' -issues.

at app.AppView is stored a Function -object named AppView. In javascript functions are used as 'classes' (don't think about Java classes!) in a system called prototype inheritance. Don't get mixed into that yet.

When you call

new app.AppView()

you create a new instance of this AppView 'class', that IS an object. So when you call

app.AppView.render()

you're trying to call the function render of the 'class' (or class-but-not-quite-a-class). Now that isn't right one bit.

So (like in Java or any other oo-language), you have to store the instance you get by calling the constructor to a variable.

var appView = new app.AppView();

Now that you have an instance, you can do whatever you like with it

appView.render();
于 2013-01-17T15:20:54.480 回答