Method Shorthand
Video
JavaScript Notes
JavaScript
/************************************
Method shorthand in ES6
************************************/
let obj = {
prop1: 123,
prop2: 'abc',
prop3: true,
prop4: function(){
console.log( obj );
console.log( this );
},
prop5: ()=>{
console.log( obj );
console.log( this );
},
prop6(){
console.log( obj )
console.log( this )
}
}
obj.prop6(); // ES6 syntax. Works the same way as obj.prop4()
obj.prop5(); // the THIS keyword does not work in arrow functions, so this line of code will log out obj, and then log out an empty object
Feedback
Submit and view feedback