code
function Person( name ) {
this.name = name
console.log(this)
}
Person.prototype.talk = function() {
console.log( "Hello " + this.name )
return this
}
Person.talk = function() {
console.log( "Hello " + this.name )
return this
}
results in console
> var me = new Person('juanma')
Person {name: "juanma"}
> me.talk()
Hello juanma
Person {name: "juanma"}
> Person.talk()
Hello Person
ƒ Person( name ) {
this.name = name
console.log(this)
}
class Person {
constructor(name) {
this.name = name
console.log(this)
}
talk() {
console.log( "Hello " + this.name )
return this
}
static talk() {
console.log( "Hello " + this.name )
return this
}
}
> var me = new Person('juanma')
Person {name: "juanma"}
> me.talk()
Hello juanma
Person {name: "juanma"}
> Person.talk()
Hello Person
class Person {
constructor(name) {
this.name = name
console.log(this)
}
talk() {
console.log( "Hello " + this.name )
return this
}
static talk() {
console.log( "Hello " + t…