Skip to content

Insane Proxy hack #329

Open
Open
@tj-commits

Description

@tj-commits
const quoteless = new Proxy({}, {
  get(_, key) {
    if(key === Symbol.unscopables) return {}
    if(key === "__global") return globalThis
    return `${key} `
  },

  has(_, __) {
    return true
  }
})

with (quoteless) {
  __global.console.log(This + is + black + magic)
}

This outputs "This is black magic" to the console.
The way this works is that when a property is accessed then it just gets the name of the property that was accessed. Using with (quoteless) makes all the properties be accessible without quoteless.property. The way we access console.log is by checking if the key is a magic word, such as __global, to access the globalThis.
My explanation is terrible, don't use it in the real repository lol

Metadata

Metadata

Assignees

No one assigned

    Labels

    new-exampleA proposal of the new example

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions