یک function به تنهایی زندگی میکنه
|
const bark = () => { console.log('wof!') } bark() |
یا
|
function bark() { console.log('wof!') } bark() |
method در واقع یک function هست که به یک object property نسبت داده شده
|
const dog = { bark: () => { console.log('wof!') }, } dog.bark() |
method میتونه به object properties دسترسی داشته باشه به شرطی که به صورت regular function تعریف شده باشه نه به صورت arrow function
|
const dog = { name: 'Roger', bark: function () { console.log(<code>I am ${this.name}. wof!</code>) }, } dog.bark() |