前提
jsのprototypeChainについて学んでいます
以下のようなクラスを定義しました.
JS
1function Todo(id, title, detail, deadLine, done) { 2 this.id = id; // int 3 this.title = title; // string 4 this.detail = detail; // string 5 this.deadLine = deadLine; // date 6 this.done = done // bool 7 8 let now = new Date() 9 this.createdAt = now.getFullYear().toString() + "-" + (now.getMonth()+1).toString() + "-" + now.getDate().toString() + " " + now.getHours().toString() + ":" + now.getMinutes().toString(); 10 delete now; 11}; 12 13Todo.prototype.getID = () => { 14 return this.id; 15}
発生している問題・エラーメッセージ
これに対し
JS
1 2let todo = new Todo(1, "test", "testest", "2018-07-25 00:13:00", false); 3console.log(todo.getID());
を実行したところ, todo.getIDの返す値はundefinedとなっていました
なぜこれがundefinedを返すのでしょうか?
ちなみに
JS
1let todo = new Todo(1, "test", "testest", "2018-07-25 00:13:00", false); 2console.log(todo)
を実行すると
JS
1Todo { 2 id: 1, 3 title: 'test', 4 detail: 'testest', 5 deadLine: '2018-07-25 00:13:00', 6 done: false, 7 createdAt: '2018-7-25 0:51' } 8
が返ってきているので値は代入されているものだと思います.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/24 17:33