所有函数都有 prototype 属性对象。
1. Object.prototype
2. Function.prototype
3. Array.prototype
4. String.prototype
5. Number.prototype
6. Date.prototype
7. …
练习:为数组对象和字符串对象扩展原型方法。
//我们能否为系统的对象的原型中添加方法,相当于在改变源码
//我希望字符串中有一个倒序字符串的方法
String.prototype.myReverse = function () {for(var i=this.length-1;i>=0;i--){console.log(this[i]);}};var str = "abcdefg";str.myReverse();String.prototype.sayHi=function () {console.log(this+"哈哈,我又变帅了");};//字符串就有了打招呼的方法var str2="小杨";str2.sayHi();

//为Array内置对象的原型对象中添加方法
Array.prototype.mySort=function () {
for(var i=0;i<this.length-1;i++){
for(var j=0;j<this.length-1-i;j++){
if(this[j]<this[j+1]){
var temp=this[j];
this[j]=this[j+1];
this[j+1]=temp;
}
}
}
};
var arr=[100,3,56,78,23,10];
arr.mySort();
console.log(arr);

