feat: allow passing args to object methods#20
feat: allow passing args to object methods#20haltcase wants to merge 3 commits intodavidchambers:masterfrom
Conversation
Add the ability to pass arguments to object methods in a space delimited format. From what I understand, this would preclude strict adherence to Python's string formatting where spaces would be valid in keys when resolving against the object.
|
I'm seeing the failure on one of the tests and will be looking into that. |
|
Thanks for the pull request. I would, though, like to keep the API as close as possible to Python's. It's worth noting that the results you desire are attainable with the current API: > '{1} {lastName} did the thing.'.format(obj, obj.getFirstName(false))
'Alec Baldwin did the thing.'
> '{1} {lastName} did the thing.'.format(obj, obj.getFirstName(true))
'Billy Baldwin did the thing.' |
Change from a `null` binding to binding the method to its object. This fixes things like prototype methods (toLowerCase).
|
@davidchambers Not a problem, I assumed that would be the case. I can close out the PR if you want and maintain my own separate fork. For my uses ( in a chat bot ), the template string is going to be set beforehand by end-users knowing they'll use things like edit: I'll ignore the lint issue then, but that's the only thing making it fail now. Ternary line! |
It's a nice patch, but I think a fork is a good idea. One day I hope to complete and merge #2, so it's important not to drift from the Python API. |
|
👍 sounds good. |
Add the ability to pass (string) arguments to object methods in a space delimited format. From what I understand, this would preclude strict adherence to Python's string formatting where spaces would be valid in keys when resolving against the object. ( and I know this has been requested or is potentially planned )
Despite that, I needed the functionality for myself and thought I'd propose it. If nothing else anyone interested can use my fork. I totally understand if it's not merged here.
Examples
( see here for a jsfiddle )
Assume all examples below use this object:
Prior to this PR, simple object method calls could be made:
The above will continue to work the same way, but this PR additionally allows for passing arguments to these functions:
Note, however, that even though I'm passing
truethe arguments passed are always strings. The function'sifonly checks for a truthy value in this simple case but if you were expecting anything else you'd have to cast it yourself ( eg. usingBooleanorNumberconstructors, orparseInt()).Given this is a string formatting library, this limitation doesn't seem like much of a limitation.