Skip to content

Commit

Permalink
Fix bug - error when module isn't defined.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Elliott committed Feb 14, 2013
1 parent 427c83e commit c78d1b0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/stampit.js
Expand Up @@ -6,7 +6,7 @@
* Copyright (c) 2013 Eric Elliott * Copyright (c) 2013 Eric Elliott
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
**/ **/

// Shim .forEach() // Shim .forEach()
if (!Array.prototype.forEach) { if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fn, scope) { Array.prototype.forEach = function (fn, scope) {
Expand All @@ -17,7 +17,7 @@ if (!Array.prototype.forEach) {
} }
}; };
} }

// Shim Object.create() // Shim Object.create()
if (!Object.create) { if (!Object.create) {
Object.create = function (o) { Object.create = function (o) {
Expand All @@ -37,28 +37,28 @@ if (!Function.prototype.bind) {
// closest thing possible to the ECMAScript 5 internal IsCallable function // closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
} }

var aArgs = Array.prototype.slice.call(arguments, 1), var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this, fToBind = this,
fNOP = function () {}, fNOP = function () {},
fBound = function () { fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis return fToBind.apply(this instanceof fNOP && oThis
? this ? this
: oThis, : oThis,
aArgs.concat(Array.prototype.slice.call(arguments))); aArgs.concat(Array.prototype.slice.call(arguments)));
}; };

fNOP.prototype = this.prototype; fNOP.prototype = this.prototype;
fBound.prototype = new fNOP(); fBound.prototype = new fNOP();

return fBound; return fBound;
}; };
} }



(function (root) { (function (root) {
'use strict'; 'use strict';

var extend = function extend(obj) { var extend = function extend(obj) {
var args = [].slice.call(arguments, 1); var args = [].slice.call(arguments, 1);
args.forEach(function (source) { args.forEach(function (source) {
Expand All @@ -71,7 +71,7 @@ if (!Function.prototype.bind) {
}); });
return obj; return obj;
}, },

stampit = function stampit(methods, state, enclose) { stampit = function stampit(methods, state, enclose) {
var fixed = { var fixed = {
methods: methods || {}, methods: methods || {},
Expand All @@ -80,23 +80,23 @@ if (!Function.prototype.bind) {
{}, {},
enclose: enclose enclose: enclose
}, },

factory = function factory(properties, enclose) { factory = function factory(properties, enclose) {
var instance = extend(Object.create(fixed.methods || {}), var instance = extend(Object.create(fixed.methods || {}),
fixed.state, properties), fixed.state, properties),
alt; alt;

if (typeof fixed.enclose === 'function') { if (typeof fixed.enclose === 'function') {
alt = fixed.enclose.call(instance); alt = fixed.enclose.call(instance);
} }

if (typeof enclose === 'function') { if (typeof enclose === 'function') {
alt = enclose.call(alt || instance); alt = enclose.call(alt || instance);
} }

return alt || instance; return alt || instance;
}; };

return extend(factory, { return extend(factory, {
create: factory, create: factory,
fixed: fixed, fixed: fixed,
Expand All @@ -114,13 +114,13 @@ if (!Function.prototype.bind) {
} }
}); });
}, },

compose = function compose() { compose = function compose() {
var args = [].slice.call(arguments), var args = [].slice.call(arguments),
initFunctions = [], initFunctions = [],
obj = stampit(), obj = stampit(),
props = ['methods', 'state']; props = ['methods', 'state'];

args.forEach(function (source) { args.forEach(function (source) {
if (source) { if (source) {
props.forEach(function (prop) { props.forEach(function (prop) {
Expand All @@ -129,13 +129,13 @@ if (!Function.prototype.bind) {
source.fixed[prop]); source.fixed[prop]);
} }
}); });

if (typeof source.fixed.enclose === 'function') { if (typeof source.fixed.enclose === 'function') {
initFunctions.push(source.fixed.enclose); initFunctions.push(source.fixed.enclose);
} }
} }
}); });

return stampit(obj.fixed.methods, obj.fixed.state, function () { return stampit(obj.fixed.methods, obj.fixed.state, function () {
initFunctions.forEach(function (fn) { initFunctions.forEach(function (fn) {
fn.call(this); fn.call(this);
Expand All @@ -146,12 +146,12 @@ if (!Function.prototype.bind) {
compose: compose, compose: compose,
extend: extend extend: extend
}); });

if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
module.exports = api; module.exports = api;
} else { } else {
root.stampit = api; root.stampit = api;
} }
}((typeof module === 'undefined' && module.exports === void 0) ? }((typeof exports === 'undefined') ?
window : window :
this)); this));

0 comments on commit c78d1b0

Please sign in to comment.