Skip to content

Instantly share code, notes, and snippets.

@oyilmaztekin
Created October 20, 2018 11:07
Show Gist options
  • Select an option

  • Save oyilmaztekin/44f226c2c8b3cc0b2b0bec89cae355de to your computer and use it in GitHub Desktop.

Select an option

Save oyilmaztekin/44f226c2c8b3cc0b2b0bec89cae355de to your computer and use it in GitHub Desktop.
function Person(firstname, lastname) {
this.firstname = firstname || 'Default';
this.lastname = lastname || 'Default2';
this.getFullName = function(firstname, lastname) {
return this.firstname + ' ' + this.lastname;
}
}
var jane = new Person('jane');
var getFormalFullName = function() {
return this.lastname + ', ' + this.firstname;
}
Person.prototype.getFormalFullName = getFormalFullName;
Person.prototype.getFullNameProto = function() {
return this.firstname + ' ' + this.lastname;
}
var john = {
firstname: 'John',
lastname: 'Doe'
}
console.log(jane.getFullName());
console.log(jane.getFormalFullName.call(john));
function Person2(firstname, lastname){
this.firstname = firstname
this.lastname = lastname
}
// john.__proto__ = jane;
// console.log(john.getFullName())
// var person2 = new Person2('prototype','cemil');
// Person2.prototype = Person.prototype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment