javascript实现key value对象
JavaScript的实现的Map,用着挺方便的,不知道性能怎么样。
自己用只有不超过10个元素,所以性能无所谓了。
/********************jsmap.js**************************/
/////// map 类
function classMap() {
this.map = new Array();
var struct = function(key,
value){
this.key = key;
this.value = value;
};
this.lookUp = function (key){
for (var i = 0; i <
this.map.length; i++)
{
if ( this.map[i].key === key )
{
return this.map[i].value;
}
}
return null;
};
this.setAt = function (key, value){
for (var i = 0; i
< this.map.length; i++)
{
if ( this.map[i].key === key )
{
this.map[i].value = value;
return;
}
}
this.map[this.map.length] = new struct(key,value);
};
this.removeKey = function removeKey(key){
var v;
for (var i =
0; i < this.map.length; i++)
{
v = this.map.pop();
if
( v.key === key )
continue;
this.map.unshift(v);
}
};
this.getCount = function(){
return
this.map.length;
};
this.isEmpty = function(){
return this.map.length <= 0;
};
}
////////////////////////////////////////////////////////////////////////////////////////////////
/********************调用***********************/
window.onload = function(){
var map = new classMap();
alert("is the map empty? " +
map.isEmpty());
// string to array
map.setAt("sw1", "aaaa
相关文档:
父窗口中有三种方式打开子窗口:
1:
window.open(URL,windowName,parameters);
2:
alert(""); //弹出信息提示对话框
confirm(""); //弹出信息确认对话框
prompt(""); //具有交互性质的对话框
3:
//创建模态你对话框
window.showModalDialog(sURL,vArguments,sFeatures)
//创建非模态对话框
window.showM ......
Marquee图片无缝滚动关键词: Marquee
先了解一下 ......
这部分说一下最近非常流行的事件代理。事件代理的实现简单来说,是把事件绑定到目标元素的祖先元素上,然后通过冒泡或捕获得到事件源,然后再判定事件源是否等于目标元素再执行回调函数。由于对目标元素的判定有时非常模糊,因此通过判定即可调用回调函数,这样,我们就达到一个监听器为许多事件源服务的目的。对于性能一向 ......
进一步理解javascript对象、数组和哈希表
在javascript中,对象实际上就是一个哈希表,比如下面这个user对象:
function user(n, a)
{
this.name = n;
this.age = a;
this.toString = function() {
return 'Name:' + ......