javascript
-
call, apply, bindjavascript 2020. 5. 28. 20:05
//Bind, call and apply var john = { name : 'John', age : 26, job : 'teacher', presentation : function(style, timeOfDay){ if (style === 'formal'){ console.log('Good' + timeOfDay + ', Ladies and gentleMen! I\m ' + this.name + ', I\'m a ' + this.job + ' and I\'m ' + this.age + ' years old.'); } else if (style === 'friendly'){ console.log('Hey! What\'s up? I\'m '+ this.name + ', I\'m a ' + this.job ..
-
closurejavascript 2020. 5. 28. 18:09
//closures function retirement(retirementAge){ var a = ' years left until retirement.' return function(yearOfBirth){ var age = 2020 - yearOfBirth; console.log((retirementAge - age) + a); } } var retirementUS = retirement(66); var retirementGermany = retirement(65); var retirementIceland = retirement(67); retirementUS(1990); retirementGermany(1990); retirementIceland(1990); //closures summary /* ..
-
Creating Objectjavascript 2020. 5. 27. 18:29
var Person = function(name,yearOfBirth, job){ this.name = name; this.yearOfBirth = yearOfBirth; this.job = job; } Person.prototype.calculateAge = function(){ console.log(2020 - this.yearOfBirth); } Person.prototype.lastNAme = 'Smith'; var john = new Person('John',1999,'teacher'); //instantiation var mark = new Person('Mark',1979,'retired'); john.calculateAge();//21 mark.calculateAge();//41 conso..
-
자바스크립트 thisjavascript 2020. 5. 22. 18:06
When a regular function code happens, then the default object is the window object, this 키워드가 일반 function 이나 그냥 불렸을 때는 window를 의미한다. 따라서 전역 객체로 정의되어 있는 것을 this.a 이런식으로 불러온다. 하지만 오브젝트 안의 메소드안에 this 가 쓰였을때의 this는 그 오브젝트를 의미하게 된다. var a = 1; function callA(){ var a = 2; console.log(this.a);//출력값 : 1//this.a이기 때문에 window에 전역변수로 선언된 a가 호출됨 console.log(a);//출력값 : 2//callA에 지역변수로 선언된 a가 호출됨 } callA(); ..
-
자바스크립트 Objectjavascript 2020. 5. 22. 03:47
/** * Objects and properties */ //Object literal var john = { firstName : 'John', lastName : 'Smith', birthYear : 1990, family : ['Jane', 'Mark', 'Bob', 'Emily'], job : 'teacher', isMarried : false } console.log(john.firstName); console.log(john['lastName']);//이런 식으로 접근하는 것도 가능하다. var x = 'birthYear'; console.log(john['birthYear']); john.job = 'designer'; console.log(john['job']); john['isMarrie..
-
자바스크립트 예제javascript 2020. 5. 22. 01:28
자바스크립트를 이용해 1)음식값을 입력받고 2)음식의 가격범주에 따라 팁을 정하고 3)음식값과 팁을 합쳐 4)각각의 총합 (총 음식값, 총 팁, 음식과 팁을 합친 값의 총계)를 보여주는 예제를 만들어 보았다. Udemy - The Complete JavaScript Course 2020 : Build Real Projects!과정의 Challenge3 과정이다. 아래 코드에 문제와 내가 해결한 답을 모두 적었다. /***************************** * CODING CHALLENGE 3 */ /* John and his family went on a holiday and went to 3 different restaurants. The bills were $124, $48 and $26..
-
자바스크립트 Truthy and Falsy values, equality operatorsjavascript 2020. 5. 21. 03:10
falsy value is a value that is considered false when evaluated falsy values : undefined, null, 0, ''(비어있는 문자), NaN All of this five different values here will be converted to false when evaluated in a true/false condition truthy value is a value that is considered true when in evaluated in an if/else statement condition. So, basically, it's all the values that are not falsy. truthy values : NOT ..