Skip to content
Foxipa
Code Completion 8 Challenges

Complete the function objects and this code

Practice function objects, call-site this, arrow functions, call/apply/bind, and constructor calls by completing real JavaScript.

Intermediate ~8 min read

Challenge 1

Write the call that uses box as this.

javascript Your answer
function read() { return this.value; }
const box = { value: 7 };
const result = read.(box);

Press Ctrl⌘Enter to check your answer

Challenge 2

Pass the two arguments as an array.

javascript Your answer
function add(a, b) { return this.base + a + b; }
const result = add.apply({ base: 10 }, );

Press Ctrl⌘Enter to check your answer

Challenge 3

Create a later-call function with a fixed receiver.

javascript Your answer
function read() { return this.value; }
const fixed = read.({ value: 9 });
console.log(fixed());

Press Ctrl⌘Enter to check your answer

Challenge 4

Return an arrow that reads the surrounding this.

javascript Your answer
const panel = { label: "Foxipa", make() { return ; } };

Press Ctrl⌘Enter to check your answer

Challenge 5

Initialize the new instance.

javascript Your answer
function User(name) {
  
}
const user = new User("Ada");

Press Ctrl⌘Enter to check your answer

Challenge 6

Call the method with its object base.

javascript Your answer
const box = { value: 4, read() { return this.value; } };
const result = ;

Press Ctrl⌘Enter to check your answer

Challenge 7

Bind a detached method back to its receiver.

javascript Your answer
const box = { value: 12, read() { return this.value; } };
const read = box.read;
const fixed = read.(box);

Press Ctrl⌘Enter to check your answer

Challenge 8

Pass the function rather than calling it.

javascript Your answer
function run(task) { return task(); }
function value() { return 7; }
const result = run();

Press Ctrl⌘Enter to check your answer