2017-04-21 39 views
0

我试图通过使用“新”类系统的新的JS语法。值未定义为参数,但不是函数调用

我有一个商店的数据。当我从这家商店调用一个功能时,它就可以工作。当我作为参数传入商店时,商店未定义。这看起来真的很奇怪...

我创建一个Note对象,并希望将它存储在我的商店对象中。

我的代码:

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.. 
    } 
} 

在我的笔记对象我有这样的构造:

class Note { 
    constructor(noteTitle, noteText, noteStore) { 
// Other stuff... 

     this.store = noteStore; // noteStore is undefined 

     // Other stuff... 
    } 

// I also tried store without "this" etc. 

感谢您的帮助!

+0

'this.store'不会被定义为'undefined',除非'CreateNote'被调用的方式是'this'不会引用'NoteController'实例,或者除非//其他东西包含回调函数。请向我们展示更多关于CreateNote的实现以及它如何被调用。 –

+0

我希望这里的这个更好:https://pastebin.com/9c0GkTyt – Question3r

回答

0

哦,我真的很抱歉!我写了this.store.AddNote(new Note(title, $("#edtNoteText").val()), this.store);,但它应该是this.store.AddNote(new Note(title, $("#edtNoteText").val(), this.store)); ...我只知道C#从编译器获得帮助:S对不起!

相关问题