Skip to content

Instantly share code, notes, and snippets.

@DanSmaR
Forked from mpj/example.js
Last active November 10, 2022 22:09
Show Gist options
  • Select an option

  • Save DanSmaR/6901a29e3a2c73ea95d52a1a2006071d to your computer and use it in GitHub Desktop.

Select an option

Save DanSmaR/6901a29e3a2c73ea95d52a1a2006071d to your computer and use it in GitHub Desktop.
Code from Fun Fun Function YouTube episode: The 'new' keyword - Object Creation in JavaScript P3
function Person(saying) {
this.saying = saying
}
Person.prototype.talk = function() {
console.log('I say:', this.saying)
}
function newFake(constructor) {
var obj = {}
Object.setPrototypeOf(obj, constructor.prototype)
var argsArray = Array.prototype.slice.apply(arguments)
return constructor.apply(obj, argsArray.slice(1)) || obj
}
var crockford = newFake(Person, 'SEMICOLANS!!!1one1')
crockford.talk()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment