Re: Gjs Lang.Class uses __proto__ to change function prototypes?



Yes, this is non standard, but it's supported by SpiderMonkey, and that's what gjs uses.
It's an implementation detail anyway, and its purpose is to have callable objects whose prototype is not Function.prototype, so that you can have
const MyClass = new Lang.Class(...);
and "MyClass instanceof Lang.Class" becomes true, even though MyClass is a constructor (function).

In any case, this kind of question is better asked in a specific mailing list, such as gnome-shell-list (most gjs devs are there) or _javascript_-list. Alternatively, you can find us in IRC (#introspection, #gnome-shell or #gnome-hackers).

Cheers,

Giovanni


2013/4/18 Nikita Churaev <lamefun x0r gmail com>
I've stumbled upon this while reading lang.js:

newClass.__proto__ = this.constructor.prototype;

where newClass is a function. Why does Gjs do this? Isn't this
non-standard?

_______________________________________________
desktop-devel-list mailing list
desktop-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/desktop-devel-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]