[canviz] r356 committed - Add a minimal implementation of Object.keys for old browsers that don'...

0 views
Skip to first unread message

can...@googlecode.com

unread,
Feb 1, 2012, 8:00:58 PM2/1/12
to canviz-...@googlegroups.com
Revision: 356
Author: ryandesign.com
Date: Wed Feb 1 17:00:04 2012
Log: Add a minimal implementation of Object.keys for old browsers that
don't have it

http://code.google.com/p/canviz/source/detail?r=356

Added:
/path/trunk/src/objectKeys.js
Modified:
/path/trunk/src/Path.js

=======================================
--- /dev/null
+++ /path/trunk/src/objectKeys.js Wed Feb 1 17:00:04 2012
@@ -0,0 +1,19 @@
+// A minimal implementation of Object.keys for old browsers that don't
have one.
+// It's not being assigned to Object.keys since it is not a complete proper
+// implementation: it does not work around the IE DontEnum bug, but that
should
+// be ok for our purposes.
+//
https://developer.mozilla.org/en/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
+
+var objectKeys = ('undefined' !== typeof Object.keys) ? Object.keys :
(function() {
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
+
+ return function(object) {
+ var keys = [];
+ for (var name in object) {
+ if (hasOwnProperty.call(object, name)) {
+ keys.push(name);
+ }
+ }
+ return keys;
+ };
+}());
=======================================
--- /path/trunk/src/Path.js Tue Jan 31 17:30:29 2012
+++ /path/trunk/src/Path.js Wed Feb 1 17:00:04 2012
@@ -1,4 +1,5 @@
//#include 'Bezier.js'
+//#include 'objectKeys.js'
//#include 'Rect.js'

var Path = exports.Path = function(segments, options) {
@@ -14,7 +15,7 @@
x_dashLength: 6,
x_dotSpacing: 4,
setOptions: function(options) {
- var keys = Object.keys(options);
+ var keys = objectKeys(options);
var keysLength = keys.length;
for (var i = 0; i < keysLength; ++i) {
var key = keys[i];
@@ -109,7 +110,7 @@
},
draw: function(ctx) {
ctx.save();
- var keys = Object.keys(this.options);
+ var keys = objectKeys(this.options);
var keysLength = keys.length;
for (var i = 0; i < keysLength; ++i) {
var key = keys[i];

Reply all
Reply to author
Forward
0 new messages