summaryrefslogtreecommitdiffstats
path: root/js.2/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js.2/utils.js')
-rw-r--r--js.2/utils.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/js.2/utils.js b/js.2/utils.js
new file mode 100644
index 0000000..859296c
--- /dev/null
+++ b/js.2/utils.js
@@ -0,0 +1,18 @@
+
+NES.Utils = {
+ arraycopy: function(src, srcPos, dest, destPos, length) {
+ for (var i=0; i<length; ++i) {
+ dest[destPos+i] = src[srcPos+i];
+ }
+ },
+
+ // http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/
+ copyPrototype: function(descendant, parent) {
+ var sConstructor = parent.toString();
+ var aMatch = sConstructor.match( /\s*function (.*)\(/ );
+ if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
+ for (var m in parent.prototype) {
+ descendant.prototype[m] = parent.prototype[m];
+ }
+ }
+}