JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 8 11 Apply 1 Slide Example

		
001window.onload = function(){	
		
002	const obj = {
		
003		age: 10
		
004	};
		
005	
		
006	//function that the apply will be on
		
007	// array elements match input parameters
		
008	const increaseAge = function(arrEl1,arrEl2,arrEl3){
		
009		this.age += arrEl1 + arrEl2 + arrEl3;
		
010		return this.age
		
011	}
		
012	
		
013	let arr = [1, 2, 3];
		
014	console.log('age before apply: '+ obj.age);
		
015	increaseAge.apply(obj, arr );
		
016	//obj.age will now have a value of 22
		
017	console.log('age after apply: '+ obj.age);
		
018}