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
plugins = []; | |
//inside of NovelScript.js | |
NovelScript["plugin"] = function(func){ | |
plugins.push(func); | |
} | |
//inside of the NovelScript function constructor | |
plugins.forEach(function(plugin){ | |
plugin(self, options); |
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
!function(window, document, undefined){ | |
function constructorObject(options){ | |
//do something with constructor object here | |
} | |
window["constructorObject"] = constructorObject; | |
}(window,document) |
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
!function(window, document, undefined){ | |
plugins = [];//Plugin storage object | |
function constructorObject(options){//object constructor | |
var self = this; //store itself for later | |
plugins.forEach(function(plugin){ | |
plugin(self, options);//pass this instance of the constructed object to the plugin | |
//the options used to construct it are also passed as well |
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
plugins.forEach(function(plugin){ | |
plugin(self, options);//pass this instance of the constructed object to the plugin | |
//the options used to construct it are also passed as well | |
}); |
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
!function(constructorObject, undefined){ | |
constructorObject.plugin(function(self, options){ | |
//Plugin constructor code goes here | |
//Now you have access to the self object and options by reference | |
if(typeof options !== "undefined" && options.property)//put some logic here... | |
self.protofunc();//call a function on itself | |
}); | |
constructorObject.prototype.protofunc = function(){// in the closure space, modify it's prototype | |
console.log("hello world!"); |
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
var myObject = new constructorObject; | |
myObject.protofunc(); |
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
!function(constructorObject){ | |
constructorObject.plugin(function(self, options){ | |
var events = {};//event parent | |
self.on = function(eventNameSpace, func){//add the function to the namespace | |
var event = events[eventNameSpace] = events[eventNameSpace]||[];//coalesce and make sure it's an array | |
func._function_id = func.name+Date.now();//give it some unique value for later | |
event.push(func);//store it | |
return self;//chain! |
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
!{ | |
//Typical API functions should go here | |
//func : function(){}.... | |
//func2 : function(options){...} | |
//Object creation methods... | |
//convenience methods here for create and expose via this | |
createObject: function(options){ | |
//constructor logic here | |
var created = Object.create(this.fn); |
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
~{ | |
func: function(){ | |
alert("hello world!") | |
} | |
}.func(); |
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
var foo = { | |
bar: { | |
//put some named functions here | |
}, | |
baz: function(){ | |
return Object.create(this.bar); | |
} | |
}.baz(); |