Last active
August 29, 2015 14:04
-
-
Save dfkaye/21591f6e41e5cb902454 to your computer and use it in GitHub Desktop.
string-module ~ create module from method on string instances
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
// 27 July 2014 | |
// String#module | |
// based on lessons from xyz project [https://github.com/dfkaye/xyz], | |
// String#as [https://gist.github.com/dfkaye/96637eda4e262dfe91ee], | |
// and Function#create [https://gist.github.com/dfkaye/04e13542abd4bf06abc9] | |
// in the xyz project, I'm thinking of changing the global-use pattern, | |
(define)(__filename) | |
// to instance-use | |
(__filename.module) | |
// which entails this on String.prototype | |
String.prototype.module = function(pathOrFn) { | |
// set up instancehandler | |
// delegate to instancehandler which in turn will | |
// delegate to pathhandler vs fnhandler | |
// and return itself or a module | |
// finally return the instancehandler | |
}; | |
// so we can do | |
('com.namespace.thing'.module) | |
('dependency/path'.as('alias')) | |
('builtin/path') | |
(function () { | |
// module.exports, require, global, etc. | |
}); | |
// or just | |
'com.namespace.thing'.module | |
('dependency/path'.as('alias')) | |
('builtin/path') | |
(function () { | |
// module.exports, require, global, etc. | |
}); |
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
// UPDATE FEB 28, 2015 | |
// __filename may be unassigned in browsers so a tool should write the | |
// browser-friendly file path | |
(__filename || 'generated/path/to/file.js').module | |
('dependency/path'.as('alias')) | |
('builtin/path') | |
(function () { | |
// module.exports, require, global, etc. | |
}); | |
// since January 2015 thinking jquery plugin style is better | |
$.module(__filename || 'generated/path/to/file.js') | |
('dependency/path'.as('alias')) | |
('builtin/path') | |
(function () { | |
// module.exports, require, global, etc. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment