JSFiddle - React, Tailwind, and code Playground

by lawrence pond

JavaScript

// Javascript



function Animal(foodType){
    this.foodType = foodType;
}

Animal.prototype.feed = function () {
    alert("Fed the animal: "+ this.foodType);
};




function Cow(color){
    this.color = color;
}
// Inheritance Magic is here chain one constructor to another
// call new animal first ant then fill in other data.
Cow.prototype = new Animal("Hay");

var c = new Cow("White/Black");
c.feed();
var test1 = c instanceof  Animal; // True
var test2 = c instanceof Cow; // true



var a = new Animal("None");
a.feed();                     // "None"
// this test is instanceof object
var test = a instanceof Animal; // true
alert(test);








function Customer(name, company){
    this.name = name;
    this.company= company;
    // non-public (e.g private)
    var mailserver = "mail.google.com";
    this.sendEmail = function(email){
      //  sendMailViaServer(mailserver);
  //      alert(email);
        alert(mailserver);
    };
}

function AnotherCustomer(name, company) {
    this.name = name;
    this.company = company;
}
AnotherCustomer.prototype.send = function(email)
{
 //   alert("email "+email);
};


function NewCustomer(name, company){
    var _namefirst = name;
    var _company = company;
    
    // create read only or write only properties
    // also if you are doing something else in the setter;
    
    Object.defineProperty(this, "name",{
        get:function(){return _namefirst;}
    });
    
    Object.defineProperty(this, "company",{
        get:function(){return _company;},
        set:function(value){_company= value;}
    });
    
}
// works no access to private/member data
AnotherCustomer.prototype.mailServer = "webmail.brinkster.com";
AnotherCustomer.prototype.sendMail = function(msg)
{
    alert(msg);
var svr = this.mailServer;
};


// instance data and static date

console.clear();

var another = new AnotherCustomer("Larry", "mycustomer");

another.send("[email protected]"); // this works;
another.sendMail("Hey buddy");



var cust=...