Added polyfills for Array::map and String::trim
Showing
1 changed file
with
24 additions
and
0 deletions
... | @@ -6,6 +6,30 @@ | ... | @@ -6,6 +6,30 @@ |
6 | # The Rivets namespace. | 6 | # The Rivets namespace. |
7 | Rivets = {} | 7 | Rivets = {} |
8 | 8 | ||
9 | # Polyfill For String::trim | ||
10 | unless String::trim | ||
11 | String::trim = -> return @.replace(/^\s\*/, '').replace(/\s\s*$/, '') | ||
12 | |||
13 | # Polyfill For Array::map | ||
14 | unless Array::map | ||
15 | Array::map = (callback) -> | ||
16 | if this is null | ||
17 | throw new TypeError "Can't convert #{this} to object" | ||
18 | O = Object(this) | ||
19 | len = O.length >>> 0 | ||
20 | |||
21 | throw new TypeError "#{callback} is not a function" unless typeof callback is 'function' | ||
22 | |||
23 | T = arguments[1] | ||
24 | A = new Array(len) | ||
25 | k = 0; | ||
26 | |||
27 | while k < len | ||
28 | A[k] = callbackfn.call(T, O[k], k, O) if k of O | ||
29 | k++ | ||
30 | |||
31 | return A | ||
32 | |||
9 | # A single binding between a model attribute and a DOM element. | 33 | # A single binding between a model attribute and a DOM element. |
10 | class Rivets.Binding | 34 | class Rivets.Binding |
11 | # All information about the binding is passed into the constructor; the DOM | 35 | # All information about the binding is passed into the constructor; the DOM | ... | ... |
-
Please register or sign in to post a comment