Changeset 39097

Show
Ignore:
Timestamp:
01/05/12 13:40:20 (17 months ago)
Author:
dankogai
Message:

c2 = new Math.Complex(c1); // now copies the instance

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/math-complex/trunk/complex.js

    r39093 r39097  
    11/* 
    2  * $Id: complex.js,v 0.10 2012/01/04 08:57:08 dankogai Exp dankogai $ 
     2 * $Id: complex.js,v 0.11 2012/01/05 04:31:57 dankogai Exp dankogai $ 
    33 * 
    44 *  Licensed under the MIT license. 
     
    1212    if (global.Math.Complex) return; 
    1313    Math.Complex = function Complex(re, im) { 
    14         if (this instanceof Math.Complex) { 
     14        if (re instanceof Math.Complex) { 
     15            return new Math.Complex(re.re, re.im); 
     16        } else if (this instanceof Math.Complex) { 
    1517            this.re = re ? 0 + re : 0; 
    1618            this.im = im ? 0 + im : 0; 
     
    3537        for (var p in methods) CPLX.prototype[p] = methods[p]; 
    3638        for (var p in methods) CPLX[p] = (function(method) { 
    37             return function() { 
    38                 var args = slice.call(arguments), 
    39                     self = args.shift(); 
     39            return function(self) { 
    4040                if (! (self instanceof CPLX)) self = new CPLX(self); 
    41                 return method.apply(self, args); 
     41                return method.apply(self, slice.call(arguments, 1)); 
    4242            } 
    4343        })(methods[p]); 
     
    150150    }); 
    151151    /* functions exported for convenience */ 
    152     global.cplx  = function(re, im) { return new CPLX(re, im) }; 
     152    global.cplx = function(re, im) { return new CPLX(re, im) }; 
    153153    global.cplxe = function(abs, arg) { 
    154154        return new CPLX(abs * Math.cos(arg), abs * Math.sin(arg));