const User = function (name, age) {
this.name = name;
this.age = age;
this.showName = function () {
console.log(this.name);
};
};
const mike = new User("Mike", 30);
class User2 {
constructor(name, age) {
this.name = name;
this.age = age;
}
showName() {
console.log(this.name);
}
}
const tom = new User2("Tom", 19);
------------------------------------------------------------------------------------------
const User = function (name, age) {
this.name = name;
this.age = age;
//this.showName = function () {
//console.log(this.name);
//};
};
User.prototype.showName = function() {
console.log(this.name);
};
const mike = new User("Mike", 30);
class User2 {
constructor(name, age) {
this.name = name;
this.age = age;
}
showName() {
console.log(this.name);
}
}
const tom = new User2("Tom", 19);
------------------------------------------------------------------------------------------
const User = function (name, age) {
this.name = name;
this.age = age;
//this.showName = function () {
//console.log(this.name);
//};
};
User.prototype.showName = function() {
console.log(this.name);
};
//const mike = new User("Mike", 30);
const mike = User("Mike", 30);
class User2 {
constructor(name, age) {
this.name = name;
this.age = age;
}
showName() {
console.log(this.name);
}
}
//const tom = new User2("Tom", 19);
const tom = User2("Tom", 19);
------------------------------------------------------------------------------------------
const User = function (name, age) {
this.name = name;
this.age = age;
//this.showName = function () {
//console.log(this.name);
//};
};
User.prototype.showName = function() {
console.log(this.name);
};
const mike = new User("Mike", 30);
class User2 {
constructor(name, age) {
this.name = name;
this.age = age;
}
showName() {
console.log(this.name);
}
}
const tom = new User2("Tom", 19);
for(const p in mike){
console.log(p);
}
for(const p in tom){
console.log(p);
}
//***********************************************************************************************************************
//***********************************************************************************************************************
Class : 상속
//extends
class Car {
constructor(color) {
this.color = color;
this.wheels = 4;
}
drive() {
console.log("drive..");
}
stop() {
console.log("STOP!");
}
}
class Bmw extends Car {
park() {
console.log("PARK");
}
}
const z4 = new Bmw("blue");
-------------------------------------------------------------------
// Class : method overriding[1]
class Car {
constructor(color) {
this.color = color;
this.wheels = 4;
}
drive() {
console.log("drive..");
}
stop() {
console.log("STOP!");
}
}
class Bmw extends Car {
park() {
console.log("PARK");
}
stop() {
console.log("OFF");
}
}
const z4 = new Bmw("blue");
-------------------------------------------------------------------
// Class : method overriding[2]
class Car {
constructor(color) {
this.color = color;
this.wheels = 4;
}
drive() {
console.log("drive..");
}
stop() {
console.log("STOP!");
}
}
class Bmw extends Car {
park() {
console.log("PARK");
}
stop() {
super.stop();
console.log("OFF");
}
}
const z4 = new Bmw("blue");
z4.stop();
-------------------------------------------------------------------
// Class : method overriding[3]
class Car {
constructor(color) {
this.color = color;
this.wheels = 4;
}
drive() {
console.log("drive..");
}
stop() {
console.log("STOP!");
}
}
class Bmw extends Car {
constructor() {
super();
this.navigation = 1;
}
park() {
console.log("PARK");
}
}
const z4 = new Bmw("blue");
z4
-------------------------------------------------------------------
// Class : method overriding[3]
class Car {
constructor(color) {
this.color = color;
this.wheels = 4;
}
drive() {
console.log("drive..");
}
stop() {
console.log("STOP!");
}
}
class Bmw extends Car {
constructor(color) {
super(color);
this.navigation = 1;
}
park() {
console.log("PARK");
}
}
const z4 = new Bmw("blue");
z4;
'개발 및 관리 > Javascript' 카테고리의 다른 글
자바스크립트 중급 강좌 #14 상속, 프로토타입(Prototype) (0) | 2022.03.21 |
---|---|
Javascript : call, apply, bind : 함수 호출 방식과 관계없이 this를 지정할 수 있음 (0) | 2022.03.18 |
JavaScript 디버깅, Java 디버깅 (0) | 2022.03.17 |
자바스크립트 예외 처리, How to Handle Errors (0) | 2022.03.16 |
자바스크립트 클로저? 간단히 핵심만 파악하기 (0) | 2022.03.15 |