JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 8 9 Call 4

		
001// Example of call without args
		
002const aBook = {
		
003  title: null,
		
004  author: null,
		
005  yearOfRelease: null,
		
006  getYearOfRelease() {
		
007    return this.yearOfRelease;
		
008  },
		
009  introduceAuthor(message) {
		
010    return `${this.author} ${message}`;
		
011  },
		
012};
		
013
		
014console.log(aBook.getYearOfRelease()); // prints null
		
015
		
016const theDaVinciCode = {
		
017  title: 'The Da Vinci Code',
		
018  author: 'Dan Brown',
		
019  yearOfRelease: 2003,
		
020};
		
021const theFirm = {
		
022	  title: 'The Firm',
		
023	  author: 'John Grisham',
		
024	  yearOfRelease: 1991
		
025};
		
026
		
027console.log(aBook.getYearOfRelease.call(theDaVinciCode)); // prints 2003
		
028
		
029// Example of call with args
		
030
		
031console.log(aBook.introduceAuthor('has not written books'));
		
032
		
033console.log(aBook.introduceAuthor.call(theFirm, 'has written a total of 100 books'));
		
034console.log(aBook.introduceAuthor.call(theDaVinciCode, 'is an American author best known for this thriller novels'))
		
035