I am just playing around with bind. And wanted to understand the below code -
let admin = {
name: "admin",
id: 1,
create() {
return `${this.name} can create`;
},
edit() {
return `${this.name} can edit`;
},
delete() {
return `${this.name} can delete`;
},
read() {
return `${this.name} can read`;
}
};
let editor = {
name: "editor",
id: 2,
edit: admin.edit.bind(this)
};
const editorEdit = admin.edit.bind(editor);
console.log(editor.edit()); // undefined can edit
console.log(editorEdit()); // editor can edit
Wanted to know what is the difference between the two console statement.