Extending Functions

29 Apr 2010
Posted by xeophin

Sometimes, you have a function already programmed, and then you need a more refined function, that takes even more parameters. Refactoring? A pain in the ass. Thank god I finally learned how to circumvent that pain:

Make a new, more refined function:

function moreComplexFunction(parameter1, parameter2, parameter3) {
    //execute stuff
}

Then replace the original code in the simple function, replacing the superfluous parameters with standard values:

function simpleFunction(parameter1, parameter2) {
    return moreComplexFunction(parameter1,parameter2,"standardValue");
}

I could hit myself for not figuring that out earlier ...

Sometimes, you have a function already programmed, and then you need a more refined function, that takes even more parameters. Refactoring? A pain in the ass. Thank god I finally learned how to circumvent that pain:Make a new, more refined function:function moreComplexFunction(parameter1, parameter2, parameter3) { //execute stuff}Then replace the original code in the simple function, replacing the superfluous parameters with standard values:function simpleFunction(parameter1, parameter2) { return moreComplexFunction(parameter1,parameter2,"standardValue");}I could hit myself for not figuring that out earlier ...

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
By submitting this form, you accept the Mollom privacy policy.


Navigation



Languages