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
{{ message }}
Make create return an instance with prototype #130
I want to override the handle function returned when create is called. However, I cannot do so because there is not way to get at the definition. How would you feel about a PR that made create return an instance with handle on the prototype?
Can you explain more of your use case? I'm pretty strongly biased against "new" and would prefer to avoid that approach, but maybe we can find another way to achieve what you need.
Hi,
I would like to be able to override the handle function in order to write a default set of rules for handling errors and success so I don't have to write the same patterns each time.
I can rewrite handle, but only on the form I have created, not on all forms I create from the form 'class'. If form.create returned an instance of a 'class', with 'handle' a prototype of that class, I could partially override the definition of handle.
You would not need to expose the uninstantiated constructor to the consumer of the interface, create could return a new instance.
However, it becomes a little awkward when I start separating code into modules because I want to export forms with a new definition of create, not a form object, as above.
You could make a new module joe-forms that takes forms, saves a reference to the original create function, makes a formCreate like the example above and sticks that on .create, and then use joe-forms instead of forms.
Activity
ljharb commentedon Jun 16, 2014
Can you explain more of your use case? I'm pretty strongly biased against "new" and would prefer to avoid that approach, but maybe we can find another way to achieve what you need.
JoeChapman commentedon Jun 16, 2014
Hi,
I would like to be able to override the handle function in order to write a default set of rules for handling errors and success so I don't have to write the same patterns each time.
I can rewrite handle, but only on the form I have created, not on all forms I create from the form 'class'. If form.create returned an instance of a 'class', with 'handle' a prototype of that class, I could partially override the definition of handle.
You would not need to expose the uninstantiated constructor to the consumer of the interface, create could return a new instance.
ljharb commentedon Jun 16, 2014
could you write a function like:
JoeChapman commentedon Jun 16, 2014
would that allow me to call the original handle function from within myHandle?
ljharb commentedon Jun 16, 2014
Sure, you could do:
JoeChapman commentedon Jun 17, 2014
However, it becomes a little awkward when I start separating code into modules because I want to export forms with a new definition of create, not a form object, as above.
ljharb commentedon Jul 5, 2014
You could make a new module
joe-formsthat takes forms, saves a reference to the originalcreatefunction, makes aformCreatelike the example above and sticks that on.create, and then usejoe-formsinstead offorms.