카테고리 없음

오늘 배운것. (아래를 뭐라고 칭해야 할지 모르겠음)

윤보람 2008. 11. 4. 19:49
<script type="text/javascript" language="javscript" src="prototype.js"></script>


Object.extend (String, {
  extendFunction : function(arg) { return arg;  }        
 });  

① 기능 : String 자체에 method추가
② 접근방법 : String.extendFunction('Love');
같은 방법 : String.extendFunction = function(arg) {  return arg;  }   


Object.extend (String.prototype, {
  extendFunction : function(arg) { return arg;  }        
 });  

① 기능 : String을 상속받는 객체에 method추가
② 접근방법 : var boram;  boram.extendFunction('Story');
같은 방법 : String.prototype.extendFunction = function(arg) {  return arg;  }   

각 프로퍼티 확인

var properties;

 for( properties in String ) {
   document.write(properties+'<br/>')
  }
                      document.write('---------------<br/>');
 for( properties in boram) {
   document.write(properties+'<br/>')
  }



prototype.js 에서  extend는 아래와 같이 정의되어 있다.

Object.extend = function(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
};

= 을 잘봐야 겠다.  언어에서 일반적인 의미가 아니라, 추가의 의미이다.




인생은 덧없이.


ㅎㅎ.... 퇴근길 지하철에서 가만히 생각해보니,,,, 이게 prototype 이네.. 
그동안 그렇게 궁금해왔던. 아.. 덧없어라.