In the course video 12 there is this file explaning all.
function Circle(radius) {
this.radius= radius;
let defaultLocation = {x : 0 ,y : 0 };
this.defaultLocation= function(){
return defaultLocation;
};
this.draw = function () {
console.log('draw');
};
Object.defineProperty(this , 'defaultLocation', {
get : function (){
return defaultLocation;
},
set : function ( value ) {
if (!value.x || ! value.y)
throw new Error('invalid Location!! CIAO');
defaultLocation = value;
}
});
}
const circle = new Circle(10);
//circle.defaultLocation = 1;
circle.draw();
I recap what i understand:
Get → read
Set → Write
Where can i found a part when i call this methods from outside?
i means …
When there is this object.defineProperties ( #1,#2,#3);
Legend :
with #1 i refer to parameter number 1
with #2 i refer to parameter number 2
with #3 i refer to parameter number 3
- #1, i will pass “this” keyword ( i undestand this ok! )
- #2 i will pass a function but where this funcion it’s called ? ( i don’t undestand this )
- #3. We pass an object for todo something like check variable with set/get ( ok undestand half …because here i found an
return defaullocation
)
when video start mosh say we want to use like
i comment this line because if i do doesn works