views:

27

answers:

2

does any one know how to check if the called ui (custom) has also options inputed or using the defaults?

for example:

$('#selector').myUI();//does not have options.
$('#selector').myUI({option:'foo',{op:'bar'}});//ui has options.
$('#selector').myUI('value');//ui has options.

so if i was on:

(function($) {
$.widget("ui.myUI", {
   options = this.options;
   //check if options have been entered or the default values have been used?
})

});

Hope that i am not 2 confusing :)

thnks

A: 

My guess is the only way to find out is to compare them against the default values.

But I'm not that familiar with the inner workings of jQuery.

Ikke
have u had the need to use the option detector?
Val
because i have come across needing it in many occasions.
Val
+1  A: 

To check whether an option has been specified, you can write

if (options.hasOwnProperty('someProperty'))
SLaks
you could do that as easy as saying `if(options.foo !='defaultValue')`but since options are optional and can be entered in any order and can be Nth number of options it's not practical checking for each option. with if statements. If im not wrong. But thank you
Val
You can use a `for in` loop.
SLaks
this would make it slow... im raising this as an idea at jquery forum... because it should be very easy to be modified on it's core... e.g: getting the length of the "arguments.length" so hopefully they take that on bord. and it's only a one line the need to add .
Val
A `for in` loop is not slow.
SLaks