Node.js(클래스)

이정규 (가지마)·2023년 6월 3일
0

클래스

-프로토타입 문법을 깔끔하게 작성할 수 있는 Class 문법 도입.

-Constructor(생성자) , Extends(상속)

구버전)

var Human = function(type){
	this.type = type|| 'human';
}

Human.isHuman = function(human){
  return human instanceof Human;
}
Human.prototype.breathe = function(){
  alert('h-a-a-a-m');
}

var Zero = function(type, firstName,lastName){
  Human.apply(this,arguments);
  this.firstName = firstName;
  this.lastName = lastName;
  

신버전

class Human{
constructor(type='human'){
this.type = type;
}

static isHuman(human){
  return human instanceof Human;
}
breathe(){
alert('h-a-a-a-m');
}
}
profile
"꾸준함이 답이다."

0개의 댓글

Powered by GraphCDN, the GraphQL CDN