summaryrefslogtreecommitdiffstats
path: root/js.2/utils.js
blob: 859296cba6b796a99606796ee408c3395e53b3d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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];
        }
    }
}