Created
August 13, 2013 17:39
-
-
Save ericelliott/6223652 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
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<section> | |
<h1 id="qunit-header">QUnit Test Suite</h1> | |
<h2 id="qunit-banner"></h2> | |
<div id="qunit-testrunner-toolbar"></div> | |
<h2 id="qunit-userAgent"></h2> | |
<ol id="qunit-tests"></ol> | |
</section> | |
<script src="jquery.js"></script> | |
<script src="qunit.js"></script> | |
<script> | |
var stampit = (function() { | |
var objectExtend = function(obj, extension) { | |
Object.getOwnPropertyNames(extension).forEach(function(key) { | |
obj[key] = copyValue(extension[key]); | |
}); | |
}; | |
var moduleExtend = function(obj, extensions) { | |
for(i = 0, count = extensions.length; i < count; i++) { | |
extensions[i].call(obj); | |
} | |
}; | |
var extend = function(props, mods, extensions) { | |
var i, count; | |
var extension; | |
for(i = 0, count = extensions.length; i < count; i++) { | |
extension = extensions[i]; | |
if (typeof extension === "function") { | |
mods.push(extension); | |
} else if (typeof extension === "object"){ | |
objectExtend(props, extension); | |
} | |
} | |
}; | |
var copyValue = function copyValue(val) { | |
var result; | |
if (Array.isArray(val)) { | |
result = []; | |
val.forEach(function(elem) { | |
result.push(copyValue(elem)); | |
}); | |
} else if (typeof val === "object") { | |
result = {}; | |
Object.keys(val).forEach(function(key) { | |
result[key] = copyValue(val[key]); | |
}); | |
} else { | |
result = val; | |
} | |
return result; | |
}; | |
var oFactory = function(proto) { | |
var factory = function(props) { | |
var obj; | |
var specs = factory.specs; | |
props = props || {}; | |
obj = Object.create(specs.proto); | |
objectExtend(obj, specs.instance_properties); | |
moduleExtend(obj, specs.instance_modules); | |
objectExtend(obj, props); | |
return obj; | |
}; | |
factory.specs = { | |
proto: proto || {}, | |
instance_modules: [], | |
instance_properties: {} | |
}; | |
factory.mixin = function() { | |
extend(this.specs.instance_properties, this.specs.instance_modules, Array.prototype.slice.call(arguments)); | |
return this; | |
}; | |
factory.shared = function() { | |
var extensions = Array.prototype.slice.call(arguments); | |
var i, count; | |
var mods = []; | |
for(i = 0, count = extensions.length; i < count; i++) { | |
extension = extensions[i]; | |
if (typeof extension === "function") { | |
mods.push(extension); | |
} else if (typeof extension === "object"){ | |
objectExtend(this.specs.proto, extension); | |
} | |
} | |
moduleExtend(this.specs.proto, mods); | |
return this; | |
}; | |
factory.compose = function() { | |
var factories = [this].concat(Array.prototype.slice.call(arguments)); | |
return oFactory.compose.apply(oFactory, factories) | |
} | |
factory.methods = factory.shared; | |
factory.state = factory.mixin; | |
factory.enclose = factory.state; | |
factory.create = factory; | |
return factory; | |
}; | |
oFactory.compose = function() { | |
var comp = oFactory(); | |
comp.specs = { | |
proto: {}, | |
instance_modules: [], | |
instance_properties: {} | |
} | |
Array.prototype.slice.call(arguments).forEach(function(f) { | |
objectExtend(comp.specs.proto, f.specs.proto); | |
objectExtend(comp.specs.instance_properties, f.specs.instance_properties) | |
Array.prototype.push.apply(comp.specs.instance_modules, f.specs.instance_modules); | |
}); | |
return comp; | |
}; | |
oFactory.mixIn = oFactory.mixin; | |
return oFactory; | |
})();</script> | |
<script>var a = stampit(); | |
var b = a();</script> | |
<script src="stampit-specs.js"></script> | |
<link href="qunit.css" rel="stylesheet"></style> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment