<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var ModuleCore = {
// add ModuleCore prototype functions to the new sub module as well as pass in the sub-modules properties and functions and return to
// the sub-module so the sub-modules prototype will have CoreModules properties and function and its own properties and function merged
// into its prototype
createModule: function(moduleObject){
var moduleCoreInstance = Object.create(this);
// add sub-modules properties and functions to CoreModule
Object.keys(moduleObject).forEach(function(key){
moduleCoreInstance[key] = moduleObject[key];
});
return moduleCoreInstance;
},
registerSidebar: function(){
console.log('registerSidebar(sidebar options for module '+this.name+')');
}
};
var bookmarksModule = ModuleCore.createModule({
name: 'bookmarks',
init: function(){
console.log('bookmarksModule init() function ran from App object '+this.name+')');
}
});
(function() {
function App() {
this.settings = {};
this.modules = {};
};
App.prototype = {
// run registerModules
init: function(bookmarksModule) {
console.log('App.init() function ran');
// call App.registerModule() and pass in bookmarksModule module name
this.registerModule('bookmarksModule', bookmarksModule);
},
// this will create a new instance of "moduleName" and add it to this.modules[moduleName] object
// for example I am hardcoding the module name as theres 1 module now
registerModule: function(moduleName, moduleClass) {
// create new instance of module
this.modules[moduleName] = new bookmarksModule();
//this.modules[moduleName] = moduleClass;
// run moduleName.init() function from the main App
this.modules[moduleName].init();
console.log('App.registerModulemoduleName) function ran and created new instance of moduleName object');
},
// itterate this.modules object and call this.initModules() function on each module object
registerModules: function() {
console.log('App.registerModules() function ran');
}
};
window.App = App;
})();
// create new instance of App
var App = new App();
App.init(bookmarksModule);
// call App.registerModule() and pass in bookmarksModule module name
App.registerModule('bookmarksModule', bookmarksModule);
//var moduleTest = new bookmarksModule();
// show bookmarksModule.name property
//console.log(moduleTest.name);
// run bookmarksModule.registerSidebar() function which is inherited from the ModuleCore object instance
//moduleTest.registerSidebar();
// bookmarksModule.init2 = function(){
// console.log('bookmarksModule init() function ran from ModuleCore module '+this.name+')');
// };
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |