swiftwasm/JavaScriptKit

Separate namespaces for methods and properties?

j-f1 opened this issue · 3 comments

j-f1 commented

Over time, it’s likely that more and more methods will be added to JSObjectRefs. Currently, there are get, set, jsValue, subscript, and (shortly) instanceof. However, at least some of these methods are likely to appear in regular JS objects (specifically get and set). While there is the escape hatch of calling object[dynamicMember: "get"] or object.get("get"), this is less than optimal and it would be great if there was a way to have a separate namespace for the JavaScriptKit-defined methods so they’d never clash with something from JS.

Maybe it would be sufficient to just add a regular subscript method object["get"] or object[1]?

Maybe it would be sufficient to just add a regular subscript method object["get"] or object[1]?

I agree with this way but there may be a more optimal way 🤔

j-f1 commented

How about this?

  • Remove the get/set methods in favor of subscripts
  • Replace object.jsValue() with an overloaded initializer JSValue(from: object)
  • Replace object.instanceof(func) with either object[instanceof: func] or JSObjectRef.instanceof(object, func)
  • Remove the get/set methods in favor of subscripts
  • Replace object.jsValue() with an overloaded initializer JSValue(from: object)
  • Replace object.instanceof(func) with either object[instanceof: func] or JSObjectRef.instanceof(object, func)

It seems that they are reasonable 👍 Could you open a new PR for these rename?