기본 콘텐츠로 건너뛰기

라벨이 javascript인 게시물 표시

javascript 상속

상속 기존의 생성자 함수나 객체를 기반으로 새로운 생성자 함수나 객체를 쉽게 만드는것. 기존의 객체를 기반으로 생성하므로 상속을 통해 새로 만들어지는 객체에는 기존 객체의 특성을 모두 가지고 있다. 1 2 3 4 5 6 7 8             //생성자 함수를 선언              function  Square( length ){                 this.width  =   length ;                 this.height  =   length ;             }             Square. prototype .getArea = function (){                  return  this.getWidth() * this.getHeight();       ...

javascript

1 2 3 var  unUncaughtException  =   function  (error) {     console.log( '예외 발생' ); }; Colored by Color Scripter cs C언어랑 c++하다가 스크립트를 하는데 이런 식으로 변수에 함수를 집어 넣어버리는건 아무리 봐도 신기 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ var을 자료형이라고 해도 되는건가?? 저놈은 메모리 공간적인 제한이 없는건가???

javascript 캡슐화

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 < script >          //생성자 함수를 선언          function  Retangle(width, height) {             this.width  =  width;             this.height  =  height;         }         Retangle. prototype .getArea  =   function  () {              return  this.width  *  this.height;         };          //변수 선언          var  rectangle  =   new ...

javascript instanceof, new 키워드

instanceof는 어떤 객체를통해 생성 됬는지 true, false값을 반환을 하여 알려준다. 1 2 3 4 5 6 7 8 9 10 11 12 13 < script >          function  Student( name ) { this. name   =   name ; }          var  student  =   new  Student( '멍개' );          alert (student instanceof Student);          alert (student instanceof  Number );          alert (student instanceof  String );          alert (student instanceof  Boolean );      < / script > cs alert (student instanceof Student);   1 2 3      alert (student instanceof  Number ); ...

javascript 프로토타입(prototype)

속성과 메서드를 분류 속성값은 매번 다른 값으로 바뀌지만 메서드는 매번 동일한 함수가 생성  메모리 공간의 낭비가 된다. 메모리 공간의 낭비를 줄이기 위해 메서드를 프로토타입으로 옮긴다. Student객체에는 이름, 수학, 영어, 과학 Student.prototype getSum() gerAverage() toString()이 저장된다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 < script >          function  Student( name , korean, math, english) {             this.이름  =   name ;             this.국어  =  korean;             this.수학  =  math;             this.영어  =  english;              }     ...