-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOM.js
More file actions
78 lines (60 loc) · 2.47 KB
/
DOM.js
File metadata and controls
78 lines (60 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(function (win, doc) {
'use strict';
function DOM(elements) {
this.element = doc.querySelectorAll(elements);
}
DOM.prototype.on = function on(eventType, callback) {
Array.prototype.forEach.call(this.element, function (element) {
element.addEventListener(eventType, callback, false);
});
this.element.addEventListener(eventType, callback, false);
}
DOM.prototype.off = function off(eventType, callback) {
Array.prototype.forEach.call(this.element, function (element) {
element.addEventListener(eventType, callback, false);
});
}
DOM.prototype.get = function get() {
return this.element;
}
DOM.prototype.forEach = function forEach() {
return Array.prototype.forEach.apply(this.element, arguments);
}
DOM.prototype.map = function map() {
return Array.prototype.map.apply(this.element, arguments);
}
DOM.prototype.filter = function filter() {
return Array.prototype.filter.apply(this.element, arguments);
}
DOM.prototype.reduce = function reduce() {
return Array.prototype.reduce.apply(this.element, arguments);
}
DOM.prototype.reduceRight = function reduceRight() {
return Array.prototype.reduceRight.apply(this.element, arguments);
}
DOM.prototype.some = function some() {
return Array.prototype.some.apply(this.element, arguments);
}
DOM.prototype.isArray = function isArray(param) {
return Object.prototype.toString.call(param) === '[object Array]';
}
DOM.prototype.isObject = function isObject(param) {
return Object.prototype.toString.call(param) === '[object Object]';
}
DOM.prototype.isFunction = function isFunction(param) {
return Object.prototype.toString.call(param) === '[object Function]';
}
DOM.prototype.isNumber = function isNumber(param) {
return Object.prototype.toString.call(param) === '[object Number]';
}
DOM.prototype.isString = function isString(param) {
return Object.prototype.toString.call(param) === '[object String]';
}
DOM.prototype.isBoolean = function isBoolean(param) {
return Object.prototype.toString.call(param) === '[object Boolean]';
}
DOM.prototype.isNull = function isNull(param) {
return Object.prototype.toString.call(param) === '[object Null]'
|| Object.prototype.toString.call(param) === '[object Underfined]';
}
})(window, document);