UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

54 lines (44 loc) 1.94 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://www.qc-net.com" rel="nofollow">Mathieu M-Gosselin</a> </strong> on 2012-06-14 03:08:04 <br /> I rewrote _copy (lines 23 to 38) to correctly take into account simple arrays (containing integers, strings or booleans) when copying, instead of casting them to objects, which caused problems when trying to access the .length property (that objects don't have, but arrays do). (I discovered that problem while using phpjs' money_format() and trying to copy locales. If, for example, the en_US LC_MONETARY.mon_grouping wasn't redefined (as it is) after cloning it from en, the thousands grouping would plainly not work, while it should. http://jsfiddle.net/jHGBR/ or <pre><code> // BEGIN STATIC var _copy = function _copy(orig) { if (orig instanceof RegExp) { return new RegExp(orig); } else if (orig instanceof Date) { return new Date(orig); } if( Object.prototype.toString.call( orig ) === '[object Array]' ) { return orig.slice(0); } else { var newObj = {}; for (var i in orig) { if (typeof orig[i] === 'object') { newObj[i] = _copy(orig[i]); } else { newObj[i] = orig[i]; } } return newObj; } };​ </code></pre> Sources: http://stackoverflow.com/questions/4690520/javascript-object-literal-length-undefined http://stackoverflow.com/questions/4775722/javascript-check-if-object-is-array http://my.opera.com/GreyWyvern/blog/show.dml/1725165 <hr /> <strong> <a href="http://an3m1.com/" rel="nofollow">????? ????</a> </strong> on 2012-05-06 09:40:36 <br /> If I might —perhaps you should consider adding a few images. I don’t mean to disrespect what you’ve said ; its very enlightening, indeed. However, I think would respond to it more positively if they could be something tangible to your ideas <hr />