Overview
Functions Properties Functions can be object properties in the same manner as any other data type.
let obj = {
add:function(a, b){
return a+b;
}
};
let sum = obj.add(4,6);
Try it!
This Variable
Functions declared on objects have the variable "this" available which points to the object on which the function is declared.
let obj = {
size:10,
getSize:function(){
return this.size;
}
};
let size = obj.getSize();
Try it!