Adding options in JavaScript functions that could use later -
i developing small javascript framework, need know how add options function, user can set own settings particular method.
this sample function method have created
$.prototype = { setcenter: function() { this.e.style.position = 'absolute'; this.e.style.top = '50%'; this.e.style.left = '50%'; this.e.style.marginleft = '-50px'; this.e.style.margintop = '-50px'; return this; } };
i expecting developed handle below options sets.
*i not using jquery, need pure javascript solution this. example code, maybe not real thing , idea.
$('samplediv').setcenter({ animate:true, fade:true });
help me solve problem, appreciate tries answer this. thank !
you implement main function way :
this.dosomething = function() { var getdefault = function(args, property, otherwise) { return args[property] !== undefined ? args[property] : otherwise; }; this.foo = getdefault(arguments, 'foo', 42); this.bar = getdefault(arguments, 'bar', false); };
so can call :
this.dosomething({foo: true});
Comments
Post a Comment