javascript - Preset Options in Object and see if it doesn't exist in allowed properties -
i trying make preset list of options allowed in object list. here code
var = function(cmd, options){ var objlist = [options.search ,options.demand]; if(!(options in objlist)){ console.warn('not allowed * in options property'); } };
or should do
var = function(cmd, options){ var objlist = [search , demand]; if(!(options in objlist)){ console.warn('not allowed option in options property'); } };
basically want set search
, demand
allowed options in options property later can do
a('cmd',{ search:'', demand:function() { alert('hello'); }, //warn next option not allowed quote: function() { alert('quote of user'); } });
if having trouble understanding asking please ask , best explain bit more.
maybe writing better?
var = function(cmd, options){ options = { theme: function(color) { $('body').css('backgroundcolor',color); }, color:'' }; }; a('cmd',{ theme:'#000'//though not working? });
you check each property in options
against array of allowed options this:
var = function(cmd, options){ var allowedoptions = ["search", "demand"]; var hasdisallowedoptions = false; (option in options) { if(allowedoptions.indexof(option) === -1 ) { hasdisallowedoptions = true; break; } } // if hasdisallowedoptions true, there disallowed option };
Comments
Post a Comment