What does the following code do:
WeatherWidget.prototype = new Widget;
where Widget
is a constructor, and I want to extend the
JavaScript functions are "MULTIPLE(2) PERSONALITIES"!!!
They are regular-functions with input and output, which we call like function()
.
Also they are constructors of JS-objects, when we use the new
keyword. >>>BUT<<< the new created objects are NOT INSTANCES of the constructors (like the objects of classes in class-based inheritance). The new objects are instances of the object of the prototype
property of the constructor.
Then in WeatherWidget.prototype =
you put the object you want to inherit its properties to the objects the constructor will create, which usually is new function()
and not a function.
JavaScript created HUGE confusion in the programming community by naming the objects created by constructors, INSTANCES of them with the instanceof
keyword.
> function f(){}
undefined
> new f() instanceof f
true