charly-lang / charly

🐈 The Charly Programming Language | Written by @KCreate
https://charly-lang.github.io/charly/
MIT License
199 stars 10 forks source link

Make Object.typeof an operator #152

Closed KCreate closed 7 years ago

KCreate commented 7 years ago

Every DataType can override the typeof method. This can lead to faulty behaviour:

let box = {
  func typeof() {
    "Numeric"
  }
}

box.typeof() // => "Numeric"

The new way would be:

typeof 5 // => "Numeric"

It's parsed via the following rule:

Expression
-> "typeof" Expression

Associativity is higher than multiplication but lower than a function call.