Skip to content

Instantly share code, notes, and snippets.

@andrewgremlich
Created April 23, 2018 18:23
Show Gist options
  • Save andrewgremlich/0733f618edac26ef83a2bff4f6835006 to your computer and use it in GitHub Desktop.
Save andrewgremlich/0733f618edac26ef83a2bff4f6835006 to your computer and use it in GitHub Desktop.
Inheritance attempt with parent and grandparent with prototypes and objects.
function superb(a, b) {
this.a = a
this.b = b
}
superb.prototype.math = function() {
return this.a + this.b
}
function duper(c, d) {
this.c = c
this.d = d
let internalProcessing = (() => {
const a = 90 * this.c
const b = 100 * this.d
superb.call(this, a, b)
})()
}
duper.prototype = Object.create(superb.prototype)
duper.prototype.hello = function() {
return 'hello'
}
function start(e) {
this.e = e
let somethingElse = (function() {
console.log('PARENT OBJECT IS WINDOW', this)
}());
let internalProcessing = (() => {
console.log('NEW OBJECT BINDING THIS', this)
const c = 90 * this.e
const d = 100 * this.e
duper.call(this, c, d)
})()
}
start.prototype = Object.create(duper.prototype)
start.prototype.multiply = function() {
return this.e * this.a
}
let cla = new start(3)
console.log(cla)
console.log(cla.math())
console.log(cla.multiply())
console.log(cla.hello())
let objInterface = {
another: function() {
return 'a function with the prototype originally out of base object'
}
}
//I guess the next two functions could be viewed as interfaces?
function superb(a, b) {
this.a = a
this.b = b
this.math = function() {
return this.a + this.b
}
}
//interface?
function duper(c, d) {
this.c = c
this.d = d
this.add = function() {
return this.c + this.d + this.e
}
let internalProcessing = (() => {
const a = 90 * this.c
const b = 100 * this.d
superb.apply(this, [a, b])
})()
}
//Base Object
//Methods will be attached to prototype chain.
let start = {
init: function(e) {
this.e = e
this.multiply = function() {
return this.e * this.a
}
let internalProcessing = (() => {
let c = 90 * this.e,
d = 100 * this.e
Object.assign(this, objInterface)
duper.apply(this, [c, d])
})()
},
something: function() {
return 'something off of base object'
}
}
//Any mention of the 'this' keyword will be the property of this object
let cla = Object.create(start)
// Object.assign(cla, objInterface)
//Don't use __proto__ ?
// Object.assign(cla.__proto__, objInterface)
cla.init(3)
console.log(cla)
console.log(cla.multiply())
console.log(cla.add())
console.log(cla.something())
console.log(cla.another())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment