Plugin Test
Just a play of method creation in JavaScript to imitate jQuery Syntax.
by rikkotec
HTML
<script type='text/javascript'>
daxleLoadMsg
(
{
message:'Manually Set!'
}
);
daxleLoadMsg();
</script>
JavaScript
// Here we define a function which will work similarly to
// functions in the jQuery library, specifically in the way
// we format the function, and with how it is called. We
// are able to implement default values.
function daxleLoadMsg(options)
{
options = extend
(
{ // default values
type: 'system',
message: 'test2'
},
options || {}
);
alert(options.message);
}
// Helper function
// 'a' contains the default values, if we find a key in 'b' -
// which contains the arguments passed in the function's call - that
// also exists in 'a', we override the default value of that key in 'a'.
function extend(a, b)
{
for( var prop in b )
{
a[prop] = b[prop];
}
return a;
}