forked from simonlc/tetr.js
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpolyfill.js
36 lines (33 loc) · 779 Bytes
/
polyfill.js
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
function ObjectClone(obj) {
var copy = (obj instanceof Array) ? [] : {};
for (var attr in obj) {
if (!obj.hasOwnProperty(attr)) continue;
copy[attr] = (typeof obj[attr] == "object")?ObjectClone(obj[attr]):obj[attr];
}
return copy;
}
function $$(id){
return document.getElementById(id);
}
function $setText(elm,s){
if(typeof elm.innerText==="string"){
elm.innerText=s;
}else{
elm.textContent=s;
}
}
function range(start, end, inc) {
inc = inc || 1;
var array = [];
for (var i = start; i < end; i += inc) {
array.push(i);
}
return array;
}
/**
* Add divisor method so we can do clock arithmetics. This is later used to
* determine tetromino orientation.
*/
Number.prototype.mod = function(n) {
return ((this % n) + n) % n;
};