Development/JavaScript, jQuery, ...(535)
-
은닉화 / 캡슐화- 12.html
은닉화 / 캡슐화 소스 코드 function Rectangle(width, height){ //지역변수는 외부에서 호출 불가(은닉화) var width = width; var height = height; this.getWidth = function(){ return width; }; this.getHeight = function(){ return height; }; this.setWidth = function(width){ //검증 if(width
-
프로토타입을 사용한 메소드 생성- 11.html
프로토타입을 사용한 메소드 생성 학습내용 (중요)프로토타입은 생성자 함수를 사용해 생성된 객체가 공통으로 가지는 공간 prototype영역 호출 메모리 영역의 효율성 증가 상속에서도 동일한 개념이 나옴 소스 코드 function Student(name, korean, math, english, science){ this.name = name; this.korean = korean; this.math = math; this.english = english; this.science = science; } //프로토타입은 생성자 함수를 사용해 생성된 객체가 공통으로 가지는 공간 //prototype영역 호출 //메모리 영역의 효율성 증가 Student.prototype.getSum = function(){ r..
-
prototype 확인- 21.html
prototype 확인 객체 리터럴 방식으로 생성된 객체는 Object.prototype 객체가 프로토타입 객체가 된다는 것을 확인 할 수 있습니다. 소스 코드 var student = { name: 'student', age: 30 }; console.log(student.toString()); console.dir(student); 출력결과 크롬 브라우저의 출력결과 Object age: 30 name: "student" __proto__: Object __defineGetter__: function __defineGetter__() { [native code] } __defineSetter__: function __defineSetter__() { [native code] } __lookupGette..
-
배열에 객체 저장- 10.html
배열에 객체 저장 학습내용 자바와 유사 동일한 패턴 사용시 소스 코드 //생성자 함수 function Student(name, korean, math, english, science){ //속성 지정 //this 전역변수로 this없으면 지역변수 this.name = name; this.korean = korean; this.math = math; this.english = english; this.science = science; //메소드 지정 this.getSum = function(){ return this.korean + this.math + this.english + this.science; }; this.getAverage = function(){ return this.getSum()/4; ..
-
09.html-생성자 함수를 이용한 객체 생성
생성자 함수를 이용한 객체 생성 2 소스 코드 //생성자 함수 function Student(name, korean, math, english, science){ //속성 지정 //this 전역변수로 this없으면 지역변수 this.name = name; this.korean = korean; this.math = math; this.english = english; this.science = science; //메소드 지정 this.getSum = function(){ return this.korean + this.math + this.english + this.science; }; this.getAverage = function(){ return this.getSum()/4; }; this.toStr..
-
생성자 함수를 이용한 객체 생성- 08.html
생성자 함수를 이용한 객체 생성 생성자 함수는 대문자로 시작, 명사형식 일반 함수는 소문자로 시작, 동사형식 소스 코드 //생성자 함수 function Person(name){ this.name = name; } //객체 생성 var mySon = new Person('홍길동'); //출력 document.write(mySon.name + ' '); document.write(mySon['name'] + ' '); 출력결과