Study
-
Transpilation With BabelStudy/JavaScript 2020. 5. 8. 21:40
Transpilation With Babel In the last exercise, you manually converted ES6 code to ES5. Although manual conversion only took you a few minutes, it is unsustainable as the size of the JavaScript file increases. Because ES6 is predictably backwards compatible, a collection of JavaScript programmers developed a JavaScript library called Babel that transpiles ES6 JavaScript to ES5. Transpilation is t..
-
Static MethodsStudy/JavaScript 2020. 5. 8. 15:30
Static Methods Sometimes you will want a class to have methods that aren’t available in individual instances, but that you can call directly from the class. Take the Date class, for example — you can both create Date instances to represent whatever date you want, and call static methods, like Date.now() which returns the current date, directly from the class. The .now() method is static, so you ..
-
Inheritance IVStudy/JavaScript 2020. 5. 8. 15:06
Inheritance IV Now that we know how to create an object that inherits properties from a parent class let’s turn our attention to methods. When we call extends in a class declaration, all of the parent methods are available to the child class. Below, we extend our Animal class to a Cat subclass. class Animal { constructor(name) { this._name = name; this._behavior = 0; } get name() { return this._..
-
Inheritance IIIStudy/JavaScript 2020. 5. 8. 14:58
Inheritance III We’ve abstracted the shared properties and methods of our Cat and Dog classes into a parent class called Animal (See below). class Animal { constructor(name) { this._name = name; this._behavior = 0; } get name() { return this._name; } get behavior() { return this._behavior; } incrementBehavior() { this._behavior++; } } Now that we have these shared properties and methods in the p..
-
Inheritance IIStudy/JavaScript 2020. 5. 8. 14:44
Inheritance II In the last exercise, we created a parent class named Animal for two child classes named Cat and Dog. The Animal class below contains the shared properties and methods of Cat and Dog. class Animal { constructor(name) { this._name = name; this._behavior = 0; } get name() { return this._name; } get behavior() { return this._behavior; } incrementBehavior() { this._behavior++; } } The..
-
Inheritance IStudy/JavaScript 2020. 5. 8. 14:36
Inheritance I Imagine our doggy daycare is so successful that we decide to expand the business and open a kitty daycare. Before the daycare opens, we need to create a Cat class so we can quickly generate Cat instances. We know that the properties in our Cat class (name, behavior) are similar to the properties in our Dog class, though, there will be some differences, because of course, cats are n..
-
Method CallsStudy/JavaScript 2020. 5. 8. 14:28
Method Calls Finally, let’s use our new methods to access and manipulate data from Dog instances. class Dog { constructor(name) { this._name = name; this._behavior = 0; } get name() { return this._name; } get behavior() { return this._behavior; } incrementBehavior() { this._behavior++; } } const halley = new Dog('Halley'); In the example above, we create the Dog class, then create an instance, a..
-
Object.keys()Study/JavaScript 2020. 5. 8. 09:30
The Object.keys() method returns an array of a given object's own enumerable property names, iterated in the same order that a normal loop would. Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually. const objec..