JS高级

1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <title></title> 6</head> 7<body> 8<script> 9 //为内置对象添加原型方法 10 //实例中的方法如果没有,就去创建该实例对象的构造函数的原型对象中找 11 //在字符串中添加一个倒序字符串的方法 12 String.prototype.myReverse = function () { 13 for (var i = this.length - 1; i >= 0; i--) { 14 console.log(this[i]); 15 } 16 }; 17 var str = "abcd"; 18 str.myReverse(); 19 //为Array内置对象的原型对象中添加方法 20 Array.prototype.mySort = function () { 21 for (var i = 1; i < this.length; i++) { 22 for (var j = 0; j < this.length - i; j++) { 23 if (this[j] > this[j + 1]) { 24 var temp = this[j]; 25 this[j] = this[j + 1]; 26 this[j + 1] = temp; 27 } 28 } 29 } 30 }; 31 32 var arr = [100, 10, 200, 30, 20, 1]; 33 arr.mySort(); 34 console.log(arr); 35</script> 36</body> 37</html>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

vue 2.0 第一个坑,组件不显示的问题

<!DOCTYPEhtml<htmllang"en"<head<metacharset"UTF8"<titleappcomponent</title</head<body<ol<todoitem</todoit

JavaScript DOM操作案例点击按钮显示图片

1<!DOCTYPEhtml2<htmllang"en"3<head4<metacharset"UTF8"5<title</title6</head7<body8<inputtype"button"v

HTML5 基础知识(二)

<!DOCTYPEhtml<htmllang"en"<head<metacharset"utf8"/<title</title</head<body</body</html<!DOCTYPEhtml