Hacker News new | ask | show | jobs
by sergeykish 2073 days ago
Yes, I know about null [[Prototype]] and who is owner of prototype and __proto__. I like how it is not real property

    var foo = {
      __proto__: null
    }
    foo.__proto__
    undefined
As you can see I do not store it and do not modify it, it is assertion, kind of instanceof.

> Also, `__proto__` is deprecated

Object.getPrototypeOf would be too verbose in this example. I could have defined

    Object.defineProperty(Object.prototype, "proto", {
      get() { Object.getPrototypeOf(this) }
    })
but why bother? We both know that I meant [[Prototype]].

> Primitive

> fn.bar = "abc"

is syntactic sugar for

fn["bar"] = "abc"

do not follow.

> (1).__proto__ === Number.prototype

number is primitive

    typeof 1
    "number"
    1 instanceof Number
    false
number is wrapped in Number when we access property

    Number.prototype.foo = function () { return this }
    1..foo()
    //Number {1}
    typeof 1..foo()
    //"object"
    1..foo() instanceof Number 
    //true
Function is not primitive

    typeof Math.max
    "function"
    Math.max instanceof Function
    true
    Math.max instanceof Object 
    true
it is an object, we can attach properties to object.

As I remember valueOf is complicated by hints, exposed in JavaScript [1]. I've played with removal

    delete Array.prototype.toString
    delete Object.prototype.toString
    Uncaught TypeError: Cannot convert object to primitive value
Unfortunately it converts to string and than converts string to number.

    delete Array.prototype.valueOf 
    delete Object.prototype.valueOf 
    +[]
    //0
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...