Skip to content
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

wrap function with multiple arguments where some arguments are optional #335

Open
minesh0111 opened this issue Oct 12, 2017 · 0 comments
Open

Comments

@minesh0111
Copy link

minesh0111 commented Oct 12, 2017

How to wrap function with multiple arguments where some arguments are optional ?

https://github.com/sstephenson/prototype/blob/d9411e5/src/prototype/lang/function.js#L337

Here is how i did it

 var Order = new Class.create();
 Order.prototype = {
    initialize : function(data){
    },
    // here arg3 and arg4 are optional parameter
    submit : function(arg1,arg2,arg3,arg4){
    	console.log(arg1);
    	console.log(arg2);
    	console.log(arg3);
    	console.log(arg4);
    }
 };

above class is defined in some third party library and below is how i have wrap it.
is this correct way to do it ?

Order.prototype.submit = Order.prototype.submit.wrap(function(callOriginal,arg1,arg2,arg3,arg4) {
        //call my custom code here;
        callOriginal(arg1,arg2,arg3,arg4);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant