// function Circle(radius) {
// this.radius = radius
// this.getArea = function(){
// return Math.PI * this.radius ** 2;
// }
// }
function Circle(radius) {
this.radius = radius
}
Circle.prototype.getArea = function(){
return Math.PI * this.radius ** 2;
}
Circle.prototype.PI = Math.PI // circle1.pi로만 접근 가능
Circle.PI = Math.PI // circle.pi로만 접근 가능(생성자이름)
const circle1 = new Circle(1);
const circle2 = new Circle(2);
console.log(circle1.getArea == circle2.getArea)
console.log(circle1.getArea === circle2.getArea)
console.log(circle1.getArea())
console.log(circle2.getArea())
console.log(circle1.PI)
console.log(circle1.__proto__.PI) // 이거랑
console.log(Circle.PI) // 이거랑 동일
console.log("--------------------")
// Date
// Date 타입의 인스턴스에 toMyString이라는 메서드를 제작 >
// yyyy-MM-DD HH:MM:SS 형태의 시간정보를 반환
Number.prototype.lz = function(){
return this < 10 ? "0" + this : ""+this;
}
Date.prototype.toMyString = function(){
return `${this.getFullYear()}/${(this.getMonth() + 1).lz()}/${this.getDate().lz()}`
+ ` ${this.getHours().lz()}:${this.getMinutes().lz()}:${this.getSeconds().lz()}`
}
const now = new Date();
console.log(now.toMyString())
const Person = (function(){
function Person(name){
this.name = name
}
Person.prototype.sayHello = function(){
console.log(`Hi! My name is ${this.name}`)
}
return Person
}())
const me = new Person('Lee')
me.sayHello()
me.sayHello = function(){
console.log(`Hi! My name is ${this.name}`)
}
me.sayHello()
// 프로퍼티 제거
delete me.sayHello;
me.sayHello;
me.sayHello()
delete Person.prototype.sayHello;
// me.sayHello();
'자바 풀스택 공부' 카테고리의 다른 글
Day 45. [Oracle SQL] 데이터 무결성 제약조건 (0) | 2022.03.10 |
---|---|
Day 44. [Oracle SQL] COMMIT, ROLLBACK, SEQUENCE, 테이블 구조만 복사, 구조 변경 (0) | 2022.03.08 |
Day 43. [ORACLE SQL] 서브쿼리와 조인, DDL DML DCL (0) | 2022.03.07 |
Day 41-4. [JavaScript] let, const 키워드와 블록 레벨 스코프 (0) | 2022.03.03 |
Day 41_3. [JavaScript] 생성자 함수, 메서드 체이닝 (0) | 2022.03.03 |
댓글