p = _.extend(Person.prototype, {a:"AAAAAAAA"});
var x = new p.constructor("some extra stuff");
console.log(x.a);
console.log(x.firstName);
/*has both a="AAAAAAA" and firstName="some extra stuff"*/
/*add stuff to the second, you can think of it as*/
class Person
{
constructor(firstName)
{
this.firstName = firstName
}
}
_.extend(Person.prototype, {addedProperty:"ssssxxxxssss"});
const p = new Person("james");
console.log(p.addedProperty);
class Person
{
constructor(firstName)
{
this.firstName = firstName
}
}
class Thing
{
constructor()
{
this.addProperty = "firstName";
}
}
_.extend(Person.prototype, Thing.property);
const p = new Person("james");
console.log(p.addedProperty);
Person = function(attributes)
{
this.attributes = attributes;
}
_.extend(Person.prototype, {test: function(){return _.clone(this.attributes)}});
const s = new Person("some test text");
console.log(s.attributes);
console.log(s.test());
/*the key to getting attributes to display is using a function(){} and _.clone()*/
/*just test: this.attributes will be undefined*/
Person = function(name)
{
this.name = name;
}
_.extend(Person.prototype, {x: function(){return this.name+"XXXXXXXXX"}});
const p = new Person("John smith");
console.log(p.x());
Person = function(name)
{
this.name = "name";
this.a = function(a)
{console.log(a)
}
this.a(this.name);
this.b();
}
_.extend(Person.prototype, {x: function(){console.log(this.name)}, b: function(){console.log("BBBBBBBBBBBBB")}});
const p= new Person("XXXX");
p.x();
the above is valid code so long as a this.name exists in the Person.prototype
the this.b() is also valid code so long as b() is added in later at the _.extend() part.