JS自定义MAP对象
2015-10-10 14:46
441 查看
/** * @version 1.0 * 用于实现页面 Map 对象,Key只能是String,对象随意 */ var Map = function(){ this._entrys = new Array(); this.put = function(key, value){ if (key == null || key == undefined) { return; } var index = this._getIndex(key); if (index == -1) { var entry = new Object(); entry.key = key; entry.value = value; this._entrys[this._entrys.length] = entry; }else{ this._entrys[index].value = value; } }; this.get = function(key){ var index = this._getIndex(key); return (index != -1) ? this._entrys[index].value : null; }; this.remove = function(key){ var index = this._getIndex(key); if (index != -1) { this._entrys.splice(index, 1); } }; this.clear = function(){ this._entrys.length = 0;; }; this.contains = function(key){ var index = this._getIndex(key); return (index != -1) ? true : false; }; this.getCount = function(){ return this._entrys.length; }; this.getEntrys = function(){ return this._entrys; }; this._getIndex = function(key){ if (key == null || key == undefined) { return -1; } var _length = this._entrys.length; for (var i = 0; i < _length; i++) { var entry = this._entrys[i]; if (entry == null || entry == undefined) { continue; } if (entry.key === key) {//equal return i; } } return -1; }; };
相关文章推荐
- jsp实现Servlet文件下载的方法
- JSP分页c:foreach分页代码以及效果新闻发布系统
- js中 parseFloat() 函数
- js权威指南——函数摘要
- 基于Raphael.js的实现
- js工具收集汇总
- js中获得项目名称
- JS正则表达式验证账号、手机号、电话和邮箱
- javascript 返回上一页面:onclick="javascript:history.back(-1);"
- 如何处理js的跨域问题
- jstl核心标签库使用
- 各大互联网公司2014前端笔试面试题–JavaScript篇
- js验证集合
- jsp获取一个对象和list对象
- soanrqube 扫描javascript代码
- JavaScript获取当前根目录
- js 设置cookie 读取cookie
- 10月17日 黑客马拉松 — 用MeteorJS开发全栈应用
- FlexPaper 里的pdf2json.exe 下载地址
- phantomjs 安装使用