Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 值未定义为参数,但不在函数调用之外_Javascript - Fatal编程技术网

Javascript 值未定义为参数,但不在函数调用之外

Javascript 值未定义为参数,但不在函数调用之外,javascript,Javascript,我正在使用“new”类系统尝试新的JS语法 我有一个存储数据的商店。当我从这个存储调用一个函数时,它就工作了。当我在对象中作为参数传入存储时,存储是未定义的。这看起来真的很奇怪 我创建了一个Note对象,并希望将其存储在我的store对象中 我的代码: class NoteController { constructor() { this.store = new NoteStore(); // Create the store object instance }

我正在使用“new”类系统尝试新的JS语法

我有一个存储数据的商店。当我从这个存储调用一个函数时,它就工作了。当我在对象中作为参数传入存储时,存储是未定义的。这看起来真的很奇怪

我创建了一个Note对象,并希望将其存储在我的store对象中

我的代码:

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
的实现以及如何调用它。我希望这里的这个更好: