You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/11 20:59:39 UTC
[1/2] js commit: [all] Adds utils.defineGetterSetter().
[all] Adds utils.defineGetterSetter().
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/1f34979b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/1f34979b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/1f34979b
Branch: refs/heads/master
Commit: 1f34979b38dd4e2876e64c265aa0a93071d43cc6
Parents: f9bcabb
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jan 11 14:04:32 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jan 11 14:04:32 2013 -0500
----------------------------------------------------------------------
lib/common/utils.js | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/1f34979b/lib/common/utils.js
----------------------------------------------------------------------
diff --git a/lib/common/utils.js b/lib/common/utils.js
index 6389e62..bfaa9cd 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.js
@@ -22,16 +22,28 @@
var utils = exports;
/**
- * Defines a property getter for obj[key].
+ * Defines a property getter / setter for obj[key].
*/
-utils.defineGetter = function(obj, key, func) {
+utils.defineGetterSetter = function(obj, key, getFunc, opt_setFunc) {
if (Object.defineProperty) {
- Object.defineProperty(obj, key, { get: func });
+ var desc = {get:getFunc};
+ if (opt_setFunc) {
+ desc.set = opt_setFunc;
+ }
+ Object.defineProperty(obj, key, desc);
} else {
- obj.__defineGetter__(key, func);
+ obj.__defineGetter__(key, getFunc);
+ if (opt_setFunc) {
+ obj.__defineSetter__(key, opt_setFunc);
+ }
}
};
+/**
+ * Defines a property getter for obj[key].
+ */
+utils.defineGetter = utils.defineGetterSetter;
+
utils.arrayIndexOf = function(a, item) {
if (a.indexOf) {
return a.indexOf(item);