Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Last active December 27, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimitarChristoff/7377464 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/7377464 to your computer and use it in GitHub Desktop.

thinking of the following change: When using options mixin and extend is on, recursively merge subclass' options with parent.prototype.options like it does in MooTools.

use case (now):

require(['prime/prime', 'prime/options'], function(prime, options){
	var a = prime({
		options: {
			x: 1,
			y: 1
		},
		implement: [options],
		constructor: function(options){
			this.setOptions(options);
		}
	});
	
	var b = prime({
		extend: a,
		// need to manually merge now.
		options: prime.merge(a.prototype.options, {
			z: 1
		})
	});
	
	console.log(new b().options);  // {x:1, y:1, z:1}
});

to change to automatic merge:

require(['prime/prime', 'prime/options'], function(prime, options){
	var a = prime({
		options: {
			x: 1,
			y: 1
		},
		implement: [options],
		constructor: function(options){
			this.setOptions(options);
		}
	});
	
	var b = prime({
		extend: a,
		options: {
			z: 1
		}
	});
	
	console.log(new b().options);  // {x:1, y:1, z:1}, currently: {z:1}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment