Javascript - curry function

jojoSmith
jojoSmith used Ask the Experts™
on
Hi,

I need to implement the curry function below to invoke the alert box on page load. This is my first time to use curry function, dont know how to do properly. Please help

var SelfEmployeeValidation = function() {
      SelfEmployeeValidation.prototype.curryGetMessage = function(){
      var add1 = this.add.curry(1);   <===
      var multi2 = this.multiply.curry(2);  <==
            if(add1(6) == 7 && multi2(4) == 8) {
            alert('you did it!')
            }
      };
      SelfEmployeeValidation.prototype.add = function(val1, val2) {
      return val1 + val2;
      };
      SelfEmployeeValidation.prototype.multiply = function(val1, val2) {
      return val1 * val2;
      };
}      

window.onload = function() {
      test = new SelfEmployeeValidation();
      test.curryGetMessage();
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
curry isn't supported by most browsers by default, you need to include the Javascript Prototype library, or another supporting library in order to use the curry function.

Author

Commented:
Many thanks for the help and quick response as this become quite urgent. I have some experience in Jquery but never do curry function as my technical lead want me to do this.

I have attached the Jquery library..
any help for the above codes
<script type="text/javascript" src="jquery-1.7.1.js"></script>

var SelfEmployeeValidation = function() {
      SelfEmployeeValidation.prototype.curryGetMessage = function(){
      var add1 = this.add.curry(1);   <===
      var multi2 = this.multiply.curry(2);  <==
            if(add1(6) == 7 && multi2(4) == 8) {
            alert('you did it!')
            }
      };
      SelfEmployeeValidation.prototype.add = function(val1, val2) {
      return val1 + val2;
      };
      SelfEmployeeValidation.prototype.multiply = function(val1, val2) {
      return val1 * val2;
      };
}      

...
my curry  function should be here...<===

Author

Commented:
How do I invoke add and multiply  curry function?

Author

Commented:
I try to change to the below, but it is wrong... please advise.

Function.prototype.curry = function() {
   var args = Array.prototype.slice.call(val1, val2);
   args.unshift(this);
   return curry.apply(this, args);
}
What error are you getting? If you are on firefox, go to Tools->Developer Tools->Error Console  or Tools->Error Console

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial