dictionary.js

function Dictionary(){
	this.datastore={};
	this.add=add;
	this.find=find;
	this.remove=remove;
	this.showAll=showAll;
}

function add(key,value){
	this.datastore[key]=value;
}

function find(key){
	return this.datastore[key];
}

function remove(key){
	delete this.datastore[key];
}

function showAll(){
	console.log(this.datastore)
	for(var key in this.datastore){
		console.log(key + ' ==> '+this.datastore[key]);
	}
}

var pbook=new Dictionary();
pbook.add('mike',"123");
pbook.add('David','456');
pbook.add('Cynthia','789');
pbook.showAll();
pbook.remove('David');
pbook.showAll();

  

posted on 2017-04-01 10:17  carlyin  阅读(91)  评论(0)    收藏  举报

导航