diff options
Diffstat (limited to 'node_modules/montage/core/shim/string.js')
-rwxr-xr-x | node_modules/montage/core/shim/string.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/node_modules/montage/core/shim/string.js b/node_modules/montage/core/shim/string.js new file mode 100755 index 00000000..1b71cec3 --- /dev/null +++ b/node_modules/montage/core/shim/string.js | |||
@@ -0,0 +1,66 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | Defines extensions to native String object. | ||
8 | @see [String class]{@link external:String} | ||
9 | @module montage/core/shim/string | ||
10 | */ | ||
11 | |||
12 | /** | ||
13 | @external String | ||
14 | */ | ||
15 | Object.defineProperties(String.prototype, /** @lends external:String.prototype#*/{ | ||
16 | /** | ||
17 | @function external:String.addEventListener | ||
18 | @param {Listener} type The type of event listener. | ||
19 | @param {Listener} listener The event listener. | ||
20 | @param {Function} useCapture The capturing function. | ||
21 | */ | ||
22 | addEventListener: { | ||
23 | value: function(type, listener, useCapture) { | ||
24 | //NO OP, on purpose | ||
25 | } | ||
26 | |||
27 | }, | ||
28 | /** | ||
29 | Capitalizes the first letter in the string. | ||
30 | @function external:String.toCapitalized | ||
31 | @returns {String} The original string with its first letter capitalized. | ||
32 | @example | ||
33 | var fname = "abe"; | ||
34 | var lname = "lincoln"; | ||
35 | var name = fname.toCapitalized() + " " + lname.toCapitalized(); | ||
36 | // name == "Abe Lincoln" | ||
37 | */ | ||
38 | toCapitalized: { | ||
39 | value: function() { | ||
40 | return this.charAt(0).toUpperCase() + this.slice(1); | ||
41 | } | ||
42 | }, | ||
43 | |||
44 | /** | ||
45 | Returns true if the two strings are equal, otherwise returns false. | ||
46 | @function external:String.equals | ||
47 | @param {Object} anObject The object to compare to the string. | ||
48 | @returns {Boolean} Returns true if the string is equal to <code>anObject</code>. | ||
49 | */ | ||
50 | equals: { | ||
51 | value: function(anObject) { | ||
52 | if (this.toString() === anObject) { | ||
53 | return true; | ||
54 | } | ||
55 | |||
56 | if (!anObject || !(anObject instanceof String)) { | ||
57 | return false; | ||
58 | } | ||
59 | |||
60 | return (this == anObject); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | }); | ||
65 | |||
66 | |||