-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.js
55 lines (49 loc) · 1.35 KB
/
common.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
jQuery.fn.reverse = function () {
return this.pushStack(this.get().reverse(), arguments);
};
function createPoint(initial) {
var _isSet = false;
var _left = undefined;
var _top = undefined;
function _change(left, top) {
_isSet = true;
_left = left;
_top = top;
}
if (initial) {
if (initial.getLeft && initial.getTop) {
_change(initial.getLeft(), initial.getTop());
}
if (initial.x && initial.y) {
_change(initial.x, initial.y);
}
if (initial.left && initial.top) {
_change(initial.left, initial.top);
}
}
return {
isSet: function () { return _isSet; },
getLeft: function () { return _left; },
getTop: function () { return _top; },
change: _change
};
}
Array.prototype.take = function (number) {
return this.splice(this.length - number);
};
Array.prototype.each = function (fn) {
var next = true;
for (var i = 0; next && i < this.length; i++) {
var result = fn(i, this[i]);
next = result === undefined || result;
}
return this;
};
//$(function () {
// var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
// alert(a.take(6));
// a.each(function (i, v) {
// alert(v);
// return v < 3
// });
//});