Last active
August 29, 2015 14:01
-
-
Save lazd/30c3a17fed9db5980080 to your computer and use it in GitHub Desktop.
Mixin Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define a class | |
| var A = Class({ | |
| toString: 'A', | |
| // Define a method | |
| method: function() { | |
| return 'ClassA'; | |
| } | |
| }); | |
| // Extend A | |
| var B = A.extend({ | |
| toString: 'B', | |
| // Add mixins to the prototype | |
| mixins: [ | |
| { | |
| method: function() { | |
| return 'Mix1'+this._super(); | |
| } | |
| }, | |
| { | |
| method: function() { | |
| return 'Mix2'+this._super(); | |
| } | |
| } | |
| ], | |
| // Override a method | |
| method: function() { | |
| return 'ClassB'+this._super(); | |
| } | |
| }); | |
| var b = new B(); | |
| // Add mixins to the instance | |
| b.mixin({ | |
| method: function() { | |
| return 'Mix4'+this._super(); | |
| } | |
| }); | |
| // Call a method | |
| b.method(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do you expect
b.method()to return?