How can I console.log this function using the call() method instead of creating a constant and using the new operator?
function Circle(radius) {
this.radius = radius;
this.draw = function() {
console.log('hi');
}
}
const another = new Circle(1);
are you trying to call draw
function without creating instance
of Circle
The lesson was saying that if we use Circle.call({}, 1)
is the same as using const another = new Circle(1);
but if the first implementation is used, I can log the circle object to the console.
call
method is change the behavior of this
as i remembered Mosh
said new Circle(1)
uses call method
behind the hood