Javascript 值未定义为参数,但不在函数调用之外
我正在使用“new”类系统尝试新的JS语法 我有一个存储数据的商店。当我从这个存储调用一个函数时,它就工作了。当我在对象中作为参数传入存储时,存储是未定义的。这看起来真的很奇怪 我创建了一个Note对象,并希望将其存储在我的store对象中 我的代码:Javascript 值未定义为参数,但不在函数调用之外,javascript,Javascript,我正在使用“new”类系统尝试新的JS语法 我有一个存储数据的商店。当我从这个存储调用一个函数时,它就工作了。当我在对象中作为参数传入存储时,存储是未定义的。这看起来真的很奇怪 我创建了一个Note对象,并希望将其存储在我的store对象中 我的代码: class NoteController { constructor() { this.store = new NoteStore(); // Create the store object instance }
class NoteController {
constructor() {
this.store = new NoteStore(); // Create the store object instance
}
CreateNote() { // Create a new note and store it
// Other stuff..
this.store.AddNote(new Note(title, $("#edtNoteText").val()), this.store);
//this.store.AddNote works fine
// this.store as a third parameter is undefined!
// Other stuff..
}
}
在我的note对象中,我有一个构造函数:
class Note {
constructor(noteTitle, noteText, noteStore) {
// Other stuff...
this.store = noteStore; // noteStore is undefined
// Other stuff...
}
// I also tried store without "this" etc.
谢谢你的帮助 哦,我真的很抱歉!!我编写了
this.store.AddNote(新注释(标题,$(“#edtNoteText”).val()),this.store)
但它应该是this.store.AddNote(新注释(标题,$(“#edtNoteText”).val(),this.store))代码>。。。我只知道C#在哪里可以从编译器那里得到帮助:对不起 this.store
不会是未定义的
,除非调用CreateNote
的方式使this
不引用NoteController
实例,或者除非//其他内容
涉及回调。请向我们展示更多的CreateNote
的实现以及如何调用它。我希望这里的这个更好: