JSFiddle - React, Tailwind, and code Playground

by Steven Senkus

JavaScript

console.log('------------START PROGRAM----------------------------------');
console.log('############################################################');
var Person = function (name) {
    this.stupidValue = 'sdafaskjdf;af';    
    this.name = name;
    this.sayName = function () {
        console.log(this.name);
        
    };
    this.announce = function () {
        console.log(this.name + ' announces');
    };
};

Person.prototype.countNewTalk = 0;
Person.prototype.updateName = function (newName) {
    var oldname = this.name;

    console.log(oldname + ' is now ' + newName);
    this.sayName = function () {
        this.name = newName;
        console.log('records show ' + oldname + ' is now ' + this.name);
        this.announce();
        Person.prototype.countNewTalk++;
    };
    
    
};

var bob = new Person('bob');

var jill = new Person('jill');
 
console.log('1---function object instance function-----------------------');
bob.sayName(); 
jill.sayName(); // 
console.log('2----prototype function alters individual instance----------');
bob.sayName();
jill.sayName();
console.log('                  2a--change bob.name ----------');
bob.updateName('Z');
bob.sayName();
console.log('                  2b--jill is not affected ----- ');
jill.sayName(); // not affected by the update
console.log('3-----------------------------------------------------------');
jill.sayName();
bob.sayName();
console.log('4-----------------------------------------------------------');
bob.sayName();
jill.updateName('SuperJill');
bob.sayName();
jill.sayName();
console.log('5-----------------------------------------------------------');
console.log(Person.prototype.countNewTalk);

console.log(Person.prototype);
// Here x is a method assigned to the object using "prototype"
var B = function () {};
B.prototype.x = function () {
    console.log('B');
};
B.prototype.updateX = function (value) {
    B.prototype.x = function () {
        console.log(value);
   ...