以下のようなクラスを書いています。
js
1export default class Notification { 2 constructor(object, confirmed = false) { 3 this.title = object.type 4 this.desc = object.desc 5 this.dateTime = object.dateTime 6 this.confirmed = confirmed 7 } 8}
このようにすると
js
1var object = {title:"question", desc: "This is question", dateTime: "today"} 2var notification = new Notification(object) 3 4console.log(notification.confirmed) 5// => undefined
となります。どのようにすればデフォルト値を定義できるでしょうか?
普通にデフォルト値取れてると思いますが? https://jsbin.com/lacupejufu/edit?js,console
回答2件
あなたの回答
tips
プレビュー