首页 > 编程语言 > 详细

js给系统对象(数组、字符串等)添加一个扩展函数

时间:2021-07-27 15:52:18      阅读:16      评论:0      收藏:0      [点我收藏+]

给系统对象加一个扩展函数: 
Array.prototype.contains = function (obj) { 
var index = this.length; 
while (index–) { 
     if (this[index] === obj) { 
         return true; 
     } 

return false; 
}

定义一个数组: 
var arr_qf = [“jpg”, “png”, “gif”, “bmp”, “html” ,”jpeg”];

调用函数,检测是否存在: 
arr_qf.contains(‘html’)

js给系统对象(数组、字符串等)添加一个扩展函数

原文:https://www.cnblogs.com/phpyangbo/p/15064756.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!