包装对象包装对象包装对象包装对象包装对象
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>无标题文档</title>
- <script>
- /*function Aaa(){
- this.name = '小明';
- }
- Aaa.prototype.showName = function(){
- alert( this.name );
- };
- var a1 = new Aaa();
- a1.showName();
- var arr = new Array();
- arr.push();
- arr.sort();
- //在JS源码 : 系统对象也是基于原型的程序
- function Array(){
- this.lenglth = 0;
- }
- Array.prototype.push = function(){};
- Array.prototype.sort = function(){};*/
- //尽量不要去修改或者添加系统对象下面的方法和属性
- var arr = [1,2,3];
- Array.prototype.push = function(){
- //this : 1,2,3
- //arguments : 4,5,6
- for(var i=0;i<arguments.length;i++){
- this[this.length] = arguments[i]
- }
- return this.length;
- };
- arr.push(4,5,6);
- alert( arr );
- //pop shift unshift splice sort
- </script>
- </head>
- <body>
- </body>
- </html>
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>无标题文档</title>
- <script>
- /*var str = 'hello';
- alert( typeof str );
- str.charAt(0);
- str.indexOf('e');*/
- //null undefined
- //包装对象 : 基本类型都有自己对应的包装对象 : String Number Boolean
- /*var str = new String('hello');
- //alert( typeof str );
- alert(str.charAt(1));
- String.prototype.charAt = function(){};*/
- //var str = 'hello';
- //str.charAt(0); //基本类型会找到对应的包装对象类型,然后包装对象把所有的属性和方法给了基本类型,然后包装对象消失
- /*var str = 'hello';
- String.prototype.lastValue = function(){
- return this.charAt(this.length-1);
- };
- alert( str.lastValue() ); //o*/
- var str = 'hello';
- str.number = 10;
- alert( str.number ); //undefined
- </script>
- </head>
- <body>
- </body>
- </html>