You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is the best approach, but just an idea
NOTE: some JS constructors don't require the use of the 'new' keyword... but others like WebAssembly.Module will and will report the following error if not used with new Uncaught TypeError: WebAssembly.Module(): WebAssembly.Module must be invoked with 'new'
Code example
API idea:
new method: pm.new
parameters: a functionwhich is a constructor
return: a functionwhich calls the constructor
---
Usage: pm.new(SomeConstructor)(parameters...)
pm.new(Function)(
I guess alternatively, better handling for JS Classes... treat JS classes like Python classes... 🤔 - I feel like that would be more complicated and confusing for users
I like the initial idea. new in JS is actually an operator which is semantically more like type() in python than construction. (JS typeof is also an operator)
Implementing this in PythonMonkey would be very straightforward. We should allow either string or function arguments. String arguments would be evaluated in the global scope to yield functions.
Activity
wiwichips commentedon Jul 23, 2023
I guess alternatively, better handling for JS Classes... treat JS classes like Python classes... 🤔 - I feel like that would be more complicated and confusing for users
wesgarland commentedon Jul 23, 2023
I like the initial idea.
newin JS is actually an operator which is semantically more like type() in python than construction. (JS typeof is also an operator)Implementing this in PythonMonkey would be very straightforward. We should allow either string or function arguments. String arguments would be evaluated in the global scope to yield functions.
would then be the same
and with this semantic, we could also
wesgarland commentedon Jul 23, 2023
See branch
feature/pm-new-bug-144