diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /node_modules/montage/core/enum.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/montage/core/enum.js')
-rwxr-xr-x | node_modules/montage/core/enum.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/node_modules/montage/core/enum.js b/node_modules/montage/core/enum.js new file mode 100755 index 00000000..309279b7 --- /dev/null +++ b/node_modules/montage/core/enum.js | |||
@@ -0,0 +1,86 @@ | |||
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 | @module montage/core/enum | ||
8 | @requires montage/core/core | ||
9 | @requires montage/core/logger | ||
10 | */ | ||
11 | var Montage = require("montage").Montage, | ||
12 | logger = require("core/logger").logger("enum"); | ||
13 | /** | ||
14 | @class module:montage/core/enum.Enum | ||
15 | @extends module:montage/core/core.Montage | ||
16 | */ | ||
17 | exports.Enum = Montage.create(Montage, /** @lends module:montage/core/enum.Enum# */ { | ||
18 | /** | ||
19 | @private | ||
20 | */ | ||
21 | _value: { | ||
22 | value: 0 | ||
23 | }, | ||
24 | /** | ||
25 | @function | ||
26 | @returns itself | ||
27 | */ | ||
28 | init : { | ||
29 | value: function() { | ||
30 | if (Object.isSealed(this)) { | ||
31 | logger.error(this, "Object is sealed"); | ||
32 | } | ||
33 | return this; | ||
34 | } | ||
35 | }, | ||
36 | /** | ||
37 | @function | ||
38 | @returns {Object} Object.seal(this) | ||
39 | */ | ||
40 | initWithMembers : { | ||
41 | value: function() { | ||
42 | if (Object.isSealed(this)) { | ||
43 | logger.error(this, "Object is sealed"); | ||
44 | return this; | ||
45 | } | ||
46 | var member, i; | ||
47 | for (i = 0; typeof (member = arguments[i]) !== "undefined"; i++) { | ||
48 | if (member !== null) { | ||
49 | this.addMember(member); | ||
50 | } else { | ||
51 | logger.error(this, "Member at index " + i + " is null"); | ||
52 | } | ||
53 | } | ||
54 | return Object.seal(this); | ||
55 | } | ||
56 | }, | ||
57 | /** | ||
58 | @function | ||
59 | @param {String} member The member to be added. | ||
60 | */ | ||
61 | addMember : { | ||
62 | value: function(member) { | ||
63 | |||
64 | if (typeof this[member] === "undefined") { | ||
65 | Object.defineProperty(this, member, { | ||
66 | writable: false, | ||
67 | configurable: false, | ||
68 | enumerable: true, | ||
69 | value: this._value | ||
70 | }); | ||
71 | this._value++; | ||
72 | } | ||
73 | } | ||
74 | }, | ||
75 | /** | ||
76 | @function | ||
77 | @returns {Object} Object.seal(this) | ||
78 | */ | ||
79 | seal : { | ||
80 | value: function() { | ||
81 | if (! Object.isSealed(this)) { | ||
82 | return Object.seal(this); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | }); | ||