前端基础-JS(四)

JS模拟一个HashTable类,包含add,remove,contains,length方法

定义类需要把函数名的第一个字母大写HashTable;
this关键字指向调用者;
为自定义的原型添加方法;
push为数组追加项;
splice时数组的方法,用来增\删\改数据

function HashTable(){
	this.value = new Array();
}

HashTable.prototype.add = function(value){
	this.value.push(value);
}

HashTable.prototype.remove = function(index){
	this.value.splice(index,1);
}

HashTable.prototype.contains = function(value){
	let aValue = this.value;
	for(let index = 0; index < aValue.length;index++){
		const element = aValue[index];
		if(value == element){
			return true;
		}
	}
	return false;
}

HashTable.prototype.length = function(index){
	this.value.length;
}

JS输出document对象中所有成员的名称和类型

document是一个对象,需要输出所有可枚举的keyvalue

for(key in document){
	document.write(key + ':' + document[key] + '<br ?>');
}

利用js生成一个table

div id="table11"></div>
	<script>
		let row;
		let cell;
		for(let index = 0;index < 10;index++){
			row = document.createElement('tr');
			document.getElementById('table11').appendChild(row);
			for(let j=0;j<5;j++){
				cell = document.createElement('td');
				cell.innerText='内容';
				row.appendChild(cell);
			}
		}
	</script>
	```



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值