본문 바로가기

개발하자/자바스크립트

prototype 으로 메서드 생성해서 공용으로 사용하기

<html>
 <body>
 <script>
 String.prototype.aaa=function(){
 return "def";
 }
 var str=new String("abc");

 document.write(str.toUpperCase()); // ABC
 document.write("<br>");
 document.write(str.aaa()); // def

 document.write("<br>");
 var str2="bbb";
 document.write(str2.aaa()); // def

 </script>
 </body>
</html>

'개발하자 > 자바스크립트' 카테고리의 다른 글

객체를 생성하는 방식 두가지  (0) 2015.02.24
event객체 visibility-visible,hidden  (0) 2015.02.24
Car.prototype.getSpeed  (0) 2015.02.24
prototype  (0) 2015.02.24
StringBuffer  (0) 2015.02.24