JSFiddle - React, Tailwind, and code Playground

by bogdan_vq

JavaScript

var Complex = (function(){
  console.log("a");
       var count = 0;

       function constructor (i, r) {
            count++;
           var imag = new String("i"+i);;
           this.real = r;

            this.setImag = function(imaginar) {
                imag = "i"+imaginar;
            };
            this.getImag = function() {
                return imag.slice(1);
            };

       }
    
        constructor.getCount = function() {    
           
           console.log(count);         
           
       }

       constructor.getJson = function(complex) {  
           return {real : complex.real};
       }

       constructor.prototype.getReal = function(){
          return this.real;
        }
        constructor.prototype.setReal = function(realMadrid){
          this.real = realMadrid;
        }

        constructor.prototype.getComplex= function(){
          return this.real +"." +this.getImag();
        }

          
        return constructor;



})();


var a = new Complex(5, 8);
console.log(a.getComplex());
console.log(a.getReal());
console.log(Complex.getJson(a));
var b = new Complex(5, 8);
var c = new Complex(5, 8);

console.log(b.getComplex());
console.log(b.getReal());
console.log(Complex.getJson(b));
console.log(Complex.getJson(b));

b.prototype.getC= function(){
          return this.real +"." +'ssss';
        }
var f = new Complex(9, 9);

console.log(f.getC());

console.log(Complex.getCount());