[understandinges6] - Understanding ECMAScript 6

Skip to first unread message

Nutan Gwari

Jun 15, 2022, 3:10:10 PM6/15/22
to Zakas Books
Hi Nicholas, 

I love reading your books. i have one question regarding Symbol.hasInstance overriding mechanism you mentioned.

Page #134
function MyObject() {

Object.defineProperty(MyObject, Symbol.hasInstance, {
    value : () => 0 // anything returned here is converted to boolean

let obj = new MyObject();   
obj instanceof MyObject // false               

My question:  although we are able to hack the hasInstance method, yet Symbols are still hiding internal logics where that Boolean step is performed, could you explain or write something about that, without that piece we are still in dark what could happen inside "magic" part of javascript.

I really enjoyed learning Symbols in JS but this small piece is stuck in my head and wanted to understand how it works under the hood.

Nutan Gwari

Nicholas Zakas

Jul 14, 2022, 2:55:48 PM7/14/22
to zakas...@googlegroups.com
Sorry for the delay, this ended up in my spam folder.

Are you saying you'd like to learn more about Symbol.hasInstance in general?

You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zakasbooks/84bb0495-0599-4031-90c8-f5394e529669n%40googlegroups.com.
Reply all
Reply to author
0 new messages