JavaScript -- Constructor、Prototype

----- 012-constructor.html -----javascript

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 5     <title>標題</title>
 6 </head>
 7 <body>
 8 <script type="text/javascript">
 9     document.write("0的構造者是:");
10     document.write((0).constructor);
11     document.write("<br/>0的構造者==Number:");
12     document.write((0).constructor==Number);
13 
14     document.write("<br/><br/>字符串的構造者是:");
15     document.write("字符串".constructor);
16     document.write("<br/>字符串的構造者==String:");
17     document.write("字符串".constructor==String);
18 </script>
19 </body>
20 </html>

----- 011-prototype.html -----html

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 5     <title>標題</title>
 6 </head>
 7 <body>
 8 <script type="text/javascript">
 9     function wo()
10     {
11         return "我是一個字符串<br/>";
12     }
13     String.prototype.me = wo;
14     var str = new String("000");
15     document.write(str.me());
16 </script>
17 </body>
18 </html>

相關文章
相關標籤/搜索