Base prime 1

Base prime

by mbread

JavaScript

BasePrimeNumberPrototype = {
  render: function() {
    return this.basePrime;
  }
};

function initial(){
  var next_prime = {
    render: function(){
      return "1";
    },
    options: function(){
      return [null,null];
    }
  };

  var next_prime_option = {
    name: "Next prime",
    follow: function(){
      return next_prime;
    }
  };
  var options = [next_prime_option];

  return{
    render: function(){
      return "0";
    },
    options: function (){
      return options;
    }
  }
}

function aeq(ex, js){
  var msg=js;
  var act=eval(js);
  if(ex !== act) document.write(msg+" expected &lt;"+ex+"&gt; but was &lt;"+act+"&gt;<br>");
}


try{

aeq("0", "Object.create(BasePrimeNumberPrototype, {basePrime:{value:'0'}}).render()");

//--------------

aeq("0", "initial().render()");

aeq(1, "initial().options().length");
aeq("Next prime", " initial().options()[0].name");

var firstPrime = "initial().options()[0].follow()";
aeq("1", firstPrime+".render()");
aeq(2, firstPrime+".options().length");
//TODO continue the prototype so I can refactor to use it to improve readability.

} catch (e){
  documentation.write(e);
}
document.write(" done");