The Now Platform® Washington DC release is live. Watch now!
If you've done any programming at all in JavaScript, then you're familiar with functions (I hope!). Normally a function looks something like this nice little message formatting function:
var x = say('${1} had a ${2} just ${3}.', 'SlightlyLoony', 'nice glass of wine', 'last night');
gs.log(x);
function say(msg, parm1, parm2, parm3) {
var x = msg.replace(/\$\{1\}/g, parm1);
x = x.replace(/\$\{2\}/g, parm2);
x = x.replace(/\$\{3\}/g, parm3);
return x;
}
var x = say('${1} had a ${2} just ${3}.', 'SlightlyLoony', 'nice glass of wine', 'last night');
gs.log(x);
function say() {
return arguments[0].replace(/\$\{([0-9]+)\}/g, replacer);
function replacer(pat, mat) {
return say.arguments[mat];
}
}
var x = sum(15, 67, 345, 22, 9352,1756);
gs.log('And the answer is: ' + x);
function sum() {
var answer = 0;
for (var i = 0; i < arguments.length; i++)
answer += arguments;
return answer;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.