Permalink
Browse files

Added deep copy

Added the addition of a deep copy parameter to get

	modified:   lib/wurfl.js
  • Loading branch information...
1 parent 5685063 commit 7bd0cea1ede15b2b27a3327117f39a6a4bee6f18 @pixeldrew pixeldrew committed Apr 16, 2012
Showing with 24 additions and 2 deletions.
  1. +24 −2 lib/wurfl.js
View
26 lib/wurfl.js
@@ -11,8 +11,15 @@ var worker;
var callbacks = {watch: {}, load: {}};
-function get(userAgent) {
- return userAgents[userAgent];
+function get(userAgent, deepcopy) {
+
+ var device = userAgents[userAgent];
+
+ if(deepcopy) {
+ device = device.deepCopy();
+ }
+
+ return device;
}
function getAll() {
@@ -163,6 +170,21 @@ function Device(attr) {
if (attr.hasOwnProperty(i)) this[i] = attr[i];
}
+Device.prototype.deepCopy = function() {
+ var dc = {}, attr = this;
+
+ for(var i in attr) {
+ dc[i] = attr[i];
+
+ for(var k in attr[i]) {
+ if(k != 'constructor')
+ dc[i][k] = attr[i][k];
+ }
+ }
+
+ return dc;
+};
+
function Group() {}

0 comments on commit 7bd0cea

Please sign in to comment.