source: Dev/trunk/src/client/util/less/build/ecma-5.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.0 KB
Line 
1
2// ecma-5.js
3//
4// -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
5// -- tlrobinson Tom Robinson
6// dantman Daniel Friesen
7
8//
9// Array
10//
11if (!Array.isArray) {
12    Array.isArray = function(obj) {
13        return Object.prototype.toString.call(obj) === "[object Array]" ||
14               (obj instanceof Array);
15    };
16}
17if (!Array.prototype.forEach) {
18    Array.prototype.forEach =  function(block, thisObject) {
19        var len = this.length >>> 0;
20        for (var i = 0; i < len; i++) {
21            if (i in this) {
22                block.call(thisObject, this[i], i, this);
23            }
24        }
25    };
26}
27if (!Array.prototype.map) {
28    Array.prototype.map = function(fun /*, thisp*/) {
29        var len = this.length >>> 0;
30        var res = new Array(len);
31        var thisp = arguments[1];
32
33        for (var i = 0; i < len; i++) {
34            if (i in this) {
35                res[i] = fun.call(thisp, this[i], i, this);
36            }
37        }
38        return res;
39    };
40}
41if (!Array.prototype.filter) {
42    Array.prototype.filter = function (block /*, thisp */) {
43        var values = [];
44        var thisp = arguments[1];
45        for (var i = 0; i < this.length; i++) {
46            if (block.call(thisp, this[i])) {
47                values.push(this[i]);
48            }
49        }
50        return values;
51    };
52}
53if (!Array.prototype.reduce) {
54    Array.prototype.reduce = function(fun /*, initial*/) {
55        var len = this.length >>> 0;
56        var i = 0;
57
58        // no value to return if no initial value and an empty array
59        if (len === 0 && arguments.length === 1) throw new TypeError();
60
61        if (arguments.length >= 2) {
62            var rv = arguments[1];
63        } else {
64            do {
65                if (i in this) {
66                    rv = this[i++];
67                    break;
68                }
69                // if array contains no values, no initial value to return
70                if (++i >= len) throw new TypeError();
71            } while (true);
72        }
73        for (; i < len; i++) {
74            if (i in this) {
75                rv = fun.call(null, rv, this[i], i, this);
76            }
77        }
78        return rv;
79    };
80}
81if (!Array.prototype.indexOf) {
82    Array.prototype.indexOf = function (value /*, fromIndex */ ) {
83        var length = this.length;
84        var i = arguments[1] || 0;
85
86        if (!length)     return -1;
87        if (i >= length) return -1;
88        if (i < 0)       i += length;
89
90        for (; i < length; i++) {
91            if (!Object.prototype.hasOwnProperty.call(this, i)) { continue }
92            if (value === this[i]) return i;
93        }
94        return -1;
95    };
96}
97
98//
99// Object
100//
101if (!Object.keys) {
102    Object.keys = function (object) {
103        var keys = [];
104        for (var name in object) {
105            if (Object.prototype.hasOwnProperty.call(object, name)) {
106                keys.push(name);
107            }
108        }
109        return keys;
110    };
111}
112
113//
114// String
115//
116if (!String.prototype.trim) {
117    String.prototype.trim = function () {
118        return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
119    };
120}
Note: See TracBrowser for help on using the repository browser.