Created
July 1, 2011 13:59
-
-
Save bgerrissen/1058592 to your computer and use it in GitHub Desktop.
This file contains 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
// some base class | |
var Dispatcher = function(){ | |
this._listeners = []; | |
} | |
Dispatcher.prototype = { | |
listen: function(){}, | |
deafen: function(){}, | |
notify: function(){} | |
} | |
// setup some governing franchise | |
var xMagazine= new Dispatcher(); | |
xMagazine.franchise = "xxx"; | |
// actually use a helper method for this, but for clarity exposing underlying techique. | |
var blush = Object.clone(xMagazine); | |
typeof blush.constructor == "function" && blush.constructor.apply(blush); | |
var yMagazine = new Dispatcher(); | |
yMagazine.franchise = "yyy"; | |
var times = Object.clone(yMagazine); | |
typeof times.constructor == "function" && times.constructor.apply(times); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So instead of creating multiple prototypical constructors, I just use one constructor and then "sub-class" instances.
This means keeping the constructor clean and argumentless, which is a good convention in my opinion.
I still want each cloned instance to have their own _listeners Array, hence the use of the .constructor property.