By Abram Adams
function build(struct data){
data["a"] = "Surprise!";
}function build(struct data){
var returnData = duplicate( data );
returnData["a"] = "No Surprises!";
return returnData;
}CF !
// Instructor: What's 5 plus 2?
numberFive().plus(numberTwo());// Student: 7?// Instructor: Correct! What's 5 plus 3?// Student: 8?// Instructor: Wrong! It's 10,
// because we turned 5 into 7, remember?a = ["Some value","Another"];
b = [ ...a, addSomething() ];
function addSomething( ){
return "Something";
}
//OUTPUT
// a: "Some value", "Another"
// b: "Some value", "Another", "Something"
a = {"product": "Jelly"};
b = {"price":"5.00"};
c = { ...a, ...b };
//OUTPUT
// c = {"product": "Jelly","price":"5.00"}Adobe
Lucee
* Array, Struct, List and Query versions
function nameIsBob(name){
return name == "bob";
}
if( nameIsBob("bob") ){
// do stuff
};
// SAME AS
if( true ){
// do stuff
}(AKA: Arrow Functions)
function makeRequest(appKey, user, url) {
if (validateAppKey(appKey)) {
if (authorizedUser(user)) {
return request(url);
} else {
return {
statusCode: 401,
message: 'user not authorized'
};
}
} else {
return {
statusCode: 401,
message: 'app not authorized.'
};
}
}makeRequest = (appKey) => (user) => (url) => {
if (validateAppKey(appKey)) {
if (authorizedUser(user)) {
return request(url);
} else {
return {
statusCode: 401,
message: 'user not authorized'
};
}
} else {
return {
statusCode: 401,
message: 'app not authorized.'
};
}
}Copied from: http://slides.com/corybrown/functional-style-js
getData = makeRequest('abc')(session.user)('https://myapi.io');getData = makeRequest('abc', session.user, 'https://myapi.io');
// Same as
getData = makeRequest('abc', session.user)('https://myapi.io');
// Same as
getData = makeRequest('abc')( session.user, 'https://myapi.io');
makeApiRequest = makeRequest('abc');
makeApiRequestAsUser = makeAppRequest(session.user);
makeApiRequestAsUser('https://myapi.io');