They are functions which function objects have.
Allows you to create preset function with arguments.
- Call: Allows you to set this variable.
- Apply: Similar to call but expects arguments as an array.
- Bind: Also allows you to set the this variable. However, it does not execute the function immediately but generates a copy of the function which can be stored.
var john = {
name: "John",
age: 26,
job: "Teacher",
presentation: function(style, timeOfDay) {
if (style === "formal") {
console.log(
"Good " +
timeOfDay +
", Ladies and gentlemen! I'm " +
this.name +
", I'm a " +
this.job +
" and I'm " +
this.age +
" years old"
);
} else if (style === "friendly") {
console.log(
"What's up? My name is " +
this.name +
", I'm a " +
this.job +
" and I'm " +
this.age +
" years old"
);
}
}
};
var emily = {
name: "Emily",
age: 35,
job: "designer"
};
john.presentation("formal", "morning");
john.presentation.call(emily, "friendly", "afternoon");
// This is currying
var johnFriendly = john.presentation.bind(john, "friendly");
johnFriendly("afternoon");
Currying
Creating a function from another function but with some preset parameters.