-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make create return an instance with prototype #130
Comments
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 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. |
could you write a function like: var formCreate = function () {
var form = forms.create.apply(forms, arguments);
form.handle = myHandle;
return form;
}; |
would that allow me to call the original handle function from within myHandle? |
Sure, you could do: var formCreate = function () {
var form = forms.create.apply(forms, arguments);
var origHandle = form.handle;
form.handle = function () {
myHandle.call(this, arguments);
return origHandle.call(this, arguments);
};
return form;
}; |
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 |
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?
The text was updated successfully, but these errors were encountered: