To ensure students have grasped the concepts discussed, let's create a summary activity where they must demonstrate their understanding of higher-order functions, constructor functions, arrow functions, generator functions, and immediately invoked function expressions (IIFEs).
This activity will test their ability to apply these concepts in a practical scenario.
Activity Instructions
Objective: Implement a mini library management system using the concepts discussed. This system will involve managing books and authors, enrolling students in classes, and generating reports.
Part 1: Constructor Functions and Prototype
Define Constructor Functions:
Create a constructor function for Author.
Create a constructor function for Book.
Prototype Methods:
Add a method to the Author prototype to return a short biography.
Add a method to the Book prototype to return a summary of the book.
Part 2: Higher-Order Functions
Array of Books:
Create an array of Book objects.
Filter Books:
Implement a higher-order function to filter books published after a certain year.
Part 3: Arrow Functions and IIFEs
Arrow Function:
Use an arrow function to list the titles of all books.
IIFE:
Create an IIFE to initialize the system with some authors and books and log the initial setup.
Part 4: Generator Functions
Generator Function:
Implement a generator function to yield books one by one.
Example Code Structure
Below is a template for students to complete the activity:
// Part 1: Constructor Functions and Prototype
// Constructor function for Author
function Author(name, birthYear) {
this.name = name;
this.birthYear = birthYear;
}
// Add a method to the Author prototype
Author.prototype.getBio = function() {
return `${this.name} was born in ${this.birthYear}.`;
};
// Constructor function for Book
function Book(title, author, publicationYear) {
this.title = title;
this.author = author; // author should be an instance of Author
this.publicationYear = publicationYear;
}
// Add a method to the Book prototype
Book.prototype.getSummary = function() {
return `${this.title}, written by ${this.author.name}, was published in ${this.publicationYear}.`;
};
// Part 2: Higher-Order Functions
const books = [
new Book("Harry Potter and the Philosopher's Stone", new Author("J.K. Rowling", 1965), 1997),
new Book("1984", new Author("George Orwell", 1903), 1949),
new Book("The Hobbit", new Author("J.R.R. Tolkien", 1892), 1937),
new Book("The Catcher in the Rye", new Author("J.D. Salinger", 1919), 1951)
Constructor Functions and Prototypes: Students should define the Author and Book constructor functions and add appropriate methods to their prototypes.
Higher-Order Functions: Implement the filterBooksByYear function to filter books by their publication year.
Arrow Functions and IIFEs: Use an arrow function to list the book titles and an IIFE to initialize and log the system setup.
Generator Functions: Create a generator function to yield books and test it by logging the summaries of the books one by one.
Evaluation Criteria
Correctness: The code should run without errors and produce the expected output.
Use of Concepts: Students should correctly apply constructor functions, prototypes, higher-order functions, arrow functions, IIFEs, and generator functions as described.
Code Quality: The code should be well-organized, readable, and follow best practices.
This activity will help students demonstrate their understanding of the key concepts discussed and how to apply them in practical scenarios.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (