본문 바로가기

Front End/JavaScript9

[JS] Constructor Function : Prototype chain 졸면서 강의 듣다가 이해하지 못한 상태에서 Coding Challenge를 하려고 하니 문제를 어떻게 풀어야할지 모르겠어서 정신 차리고 다시 집중해서 강의를 들었다. Constructor Function을 이용하는 이유는, 같은 코드를 똑같이 반복해서 쓰지 않고 같은 속성의 object를 만들기 위함이다. const Person = function(firstName, birthYear) { this.firstName = firstName; this.birthYear = birthYear; }; Person.prototype.calcAge = function() { console.log(2037 - `${this.birthYear}`) }; const Student = function(firstName, .. 2021. 6. 15.
[JS] ES6 Classes // class expression // const PersonCl = class {} // class declaration class PersonCl = { constructor(firstName, birthYear) { this.firstName = firstName; this.birthYear = birthYear; } // Method will be added to .prototype property calcAge() { console.log(2037 - this.birthYear) } greet() { console.log(`Hello ${this.firstName}`) } } const fuse = PersonCl('Fuse', 1994) console.log(fuse) // PersonCl .. 2021. 6. 14.
[JS] The Complete JavaScript Course 2021: From Zero to Expert! | # 165 Test Data const dogs = [ { weight: 22, curFood: 250, owners: ['Alice', 'Bob'] }, { weight: 8, curFood: 200, owners: ['Matilda'] }, { weight: 13, curFood: 275, owners: ['Sarah', 'John'] }, { weight: 32, curFood: 340, owners: ['Michael'] }, ]; Your tasks: 1. Loop over the 'dogs' array containing dog objects, and for each dog, calculate the recommended food portion and add it to the object as a new.. 2021. 6. 8.
[JS] The Modern JavaScript Tutorial | JS Fundamentals | Loops: while and for Repeat until the input is correct (importance: 5) Write a loop which prompts for a number greater than 100. If the visitor enters another number – ask them to input again. The loop must ask for a number until either the visitor enters a number greater than 100 or cancels the input/enters an empty line. Here we can assume that the visitor only inputs numbers. There’s no need to implement a specia.. 2021. 5. 18.