question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES3 Implementation

See original GitHub issue

IE6 compatible. Just for fun. Nothing serious. Tell me what you think about this 😄

function Mixin1 (superClass) {
  function Mixin1 () {
    // Passing constructor arguments
    superClass.apply(this, arguments)
  }
  Mixin1.prototype = new superClass()
  // Calling super class method
  Mixin1.prototype.callSuperClassMethodExample = function () {
    superClass.prototype.superClassMethod()
    return this
  }
  return Mixin1
}

function Mixin2 (superClass) {
  function Mixin2 () {
    superClass.apply(this, arguments)
  }
  Mixin2.prototype = new superClass()
  Mixin2.prototype.anotherMixinMethod = function () {
    alert('Hello from mixin!')
  }
  return Mixin2
}

// Composing mixins
function Mixin3 (superClass) {
  return Mixin2(Mixin1(superClass))
}

// Test it
var Foo = (function () {
  function Foo () {
  }
  Foo.prototype.superClassMethod = function () {
    alert('Hello from superClass!')
  }
  return Mixin3(Foo)
}())

new Foo().callSuperClassMethodExample().anotherMixinMethod()

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
trusktrcommented, Jul 14, 2016

Mixin1.prototype = new superClass()

I don’t think you should use new there, since that might run logic meant for the instance when the instance is created, not when the class is defined. I think you can use Object.create (polyfill), if that works in ES3?

Mixin1.prototype = Object.create(superClass.prototype)
0reactions
trusktrcommented, Apr 7, 2017

superClass.apply(this, arguments); // Transfer statics.

Oh yep, forgot about those. I think you meant Object.assign(IcedFrisbyNock, superClass);, but yeah, good point, ES6 classes do that automatically too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adobe LiveCycle ES3 * Implementation overview
Implement the existing service interface while providing a custom implementation for the service. For example, to provide custom implementation for ...
Read more >
[MS-ES3]: Microsoft Implementations
The following Microsoft products implement some portion of the ECMAScript Third Edition specification [ECMA-262-1999]: Windows Internet.
Read more >
ES3 Grant Application Companion 22-23
The Enhancing Social and Emotional Skills in Students with IEPs (ES3) discretionary grant provides public school districts with the structures and processes ...
Read more >
medikoo/es3-ext: ECMAScript 3 extensions (with ... - GitHub
Provides just basic utilities (and shims) which help setup basic configurations in ES3 engines. See es5-ext project for extensive list of ECMAScript 5...
Read more >
Using JavaScript Next Features in an ES3 Enterprise World
I wish it was possible for everyone to use the newer JavaScript features immediately after being finalized and implemented. Browsers and the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found