JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 8 17 Bind 2

		
001window.onload = ()=> 
		
002{
		
003	const aBook = {
		
004	  title: null,
		
005	  author: null,
		
006	  yearOfRelease: null,
		
007	  getYearOfRelease() {
		
008		return this.yearOfRelease;
		
009	  },
		
010	  introduceAuthor(message) {
		
011		return `${this.author} ${message}`;
		
012	  },
		
013	};
		
014
		
015	const theDaVinciCode = {
		
016	  title: 'The Da Vinci Code',
		
017	  author: 'Dan Brown',
		
018	  yearOfRelease: 2003
		
019	}
		
020
		
021	const theFirm = {
		
022	  title: 'The Firm',
		
023	  author: 'John Grisham',
		
024	  yearOfRelease: 1991
		
025	}
		
026
		
027	// using bind
		
028	const boundFunction1 = aBook.getYearOfRelease.bind(theFirm);
		
029	console.log(boundFunction1()); // logs 1991
		
030	const boundFunction2 = aBook.getYearOfRelease.bind(theDaVinciCode);
		
031	console.log(boundFunction2()); // logs 2003
		
032}
		
033