Skip to content

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

@minesh0111

Description

@minesh0111

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);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions