========================
function Map() {
this.elements = {};
this.length = 0;
}
Map.prototype.put = function(key,value) {
this.length++;
this.elements[key] = value;
}
Map.prototype.get = function(key) {
return this.elements[key];
}
var map = new Map();
map.put("name","값");
console.log(map.get("name"));
console.log(map.length);
========================
function List() {
this.elements = {};
this.idx = 0;
this.length = 0;
}
List.prototype.add = function(element) {
this.length++;
this.elements[this.idx++] = element;
};
List.prototype.get = function(idx) {
return this.elements[idx];
};
var list = new List();
list.add("값1");
list.add("값2");
console.log(list.get(0));
console.log(list.get(1));
console.log(list.length);
'Programming > JavaScript' 카테고리의 다른 글
[javascript] undefined, null 체크 함수 (0) | 2020.05.19 |
---|---|
체크박스 갯수확인 및 갯수제한 (0) | 2016.09.29 |
radio 버튼 체크 된 값 가져오기 (0) | 2016.08.05 |
checkbox 값 가져오기. (0) | 2016.08.03 |
jqModal 자식창 안 닫힐 떄 (0) | 2016.07.18 |