I'm trying to create a javascript framework by myself(so no jquery,mootools... code please) and I want to make the code for my framework only accessible in a framework function so for example, something like this:
frameworkname({
//framework code here
});
so my framework code doesn't conflict with other frameworks. I know that frameworkname({});
is a function, but I don't know how you pass code as a function argument. I know this is possible as I'm quite experienced in jquery and jquery has that stuff everywhere (example:$(document).ready(function(){//codehere});
), but how did the jquery developers do this? I want to be able to do this for my framework. Any help is greatly appreciated.
Functions are first class objects in JavaScript. You can pass them around in the same way as Strings, Numbers, Arrays or any other data type.
var foo = function () { alert(1); };
var bar = function (arg) { arg(); }
bar(foo);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With