JSFiddle - React, Tailwind, and code Playground
JavaScript
// 생성자 함수(class)이므로 첫글자도 대문자로 표기
function MyClass() {
this.name = '맴버변수';
}
// prototype으로 getName을 선언
MyClass.prototype.getName = function() {
// this.name을 문자열과 함께 출력
alert('name = ' + this.name);
}
// prototype의 사용을 위해 new키워드로 인스턴스화
var objClass = new MyClass();
objClass.getName();