반응형
//#객체지향
// Prototype - based programming (자바스크립트의 객체) - 객체지향의 특성을 가지면서도, 함수적특성이 있음
var person = {} //object를 담는 그릇을 설정
//person의 객체 : name / persion의 메소드 : introduce
person.name = 'Developer';
person.introduce = function() {
return 'My name is ' + this.name + '
';
}
//var person 의 object를 담는 그릇 불러오고, person의 introduce메소드불러옴
document.write(person.introduce());
//#함수 Person 선언
function Person() {
}
//a는 Person{}의 객체 생성
var a = new Person();
//a 라는 생성자 안에 변수와 함수 선언
a.name = 'Helloworld'
a.introduce = function() {
return 'My name is ' + this.name + '
';
}
//생성자 a의 메소드 호출
document.write(a.introduce());
//#생성자 초기화 함수Init()
function Init(name) {
this.name = name;
this.introduce = function() {
return 'My name is ' + this.name + '
';
}
}
//생성자 test1에 TESTNAME_1 선언
//Init 인자값 TESTNAME_1 이 Init(name)의 매개변수에 전달받고
//this.name에 저장됨
var test1 = new Init('TESTNAME_1');
document.write(test1.introduce() + '
');
var test2 = new Init('TESTNAME_2');
document.write(test2.introduce() + '
')
//#전역 객체(Global object)
function global_object() {
alert('Hello');
}
function window_global_object() {
alert('World')
}
//웹 브라우저, 자바스크립트의 모든 전역변수와 함수는 window 객체의 프로퍼티임
//따로 명시하지 않으면 암시적으로 window의 프로퍼티로 간주됨
global_object();
window.window_global_object();
반응형
'IT STUDY' 카테고리의 다른 글
| JavaScript - 표준 내장 객체 & 레퍼객체 & 참조 (0) | 2020.02.20 |
|---|---|
| JavaScript - apply call, 상속 (0) | 2020.02.18 |
| JavaScript - 클로젯, 외부,내부함수,arguments (0) | 2020.02.17 |
| JavaScript - 함수처리, 함수호출(sum.apply()) (0) | 2020.02.17 |
| JavaScript - 유효범위(전역,지역변수,scope) (0) | 2020.02.17 |