Changeset 19827
- Timestamp:
- 11/27/15 11:09:59 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/array/arrayoperations.js
r19823 r19827 309 309 return true; 310 310 } //}}} 311 function clone(obj) {//{{{ 312 313 var copy; 314 315 // Handle the 3 simple types, and null or undefined 316 if (null == obj || "object" != typeof obj) return obj; 317 318 // Handle Date 319 if (obj instanceof Date) { 320 copy = new Date(); 321 copy.setTime(obj.getTime()); 322 return copy; 323 } 324 325 // Handle Array 326 if (obj instanceof Array) { 327 copy = []; 328 for (var i = 0, len = obj.length; i < len; i++) { 329 copy[i] = clone(obj[i]); 330 } 331 return copy; 332 } 333 334 // Handle Object 335 if (obj instanceof Object) { 336 copy = {}; 337 for (var attr in obj) { 338 if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]); 339 } 340 return copy; 341 } 342 343 throw new Error("Unable to copy obj! Its type isn't supported."); 344 } //}}}
Note:
See TracChangeset
for help on using the changeset viewer.