You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constructors in Javascript are of course just functions with some special treatment. by extending Function using the ES6 class syntax you create a class that, when instantiated, is now a function, which you can then additionally instantiate.
While not exhaustively tested, I believe the last JS statement can be analyzed thus:
As a tiny addendum, doing new Function('return "bar";') of course creates a function with the body return "bar";. Since super() in the constructor of our Foo class is calling Function's constructor, it should come as no surprise now to see that we can additionally manipulate things in there.
classFooextendsFunction{constructor(val){super(` this.val = arguments[0]; `);this.prototype.val=val;}}varfoo=newnewFoo(':D')('D:');foo.val// -> 'D:'deletefoo.val;// remove the instance prop 'val', deferring back to the prototype's 'val'.foo.val// -> ':D'
The text was updated successfully, but these errors were encountered:
I present this as an oddity for your amusement.
Constructors in Javascript are of course just functions with some special treatment. by extending Function using the ES6 class syntax you create a class that, when instantiated, is now a function, which you can then additionally instantiate.
While not exhaustively tested, I believe the last JS statement can be analyzed thus:
As a tiny addendum, doing
new Function('return "bar";')
of course creates a function with the bodyreturn "bar";
. Sincesuper()
in the constructor of ourFoo
class is callingFunction
's constructor, it should come as no surprise now to see that we can additionally manipulate things in there.The text was updated successfully, but these errors were encountered: