tags:

views:

45

answers:

1

can someone explain what this function is doing

var page = new Object();  
page.testSearch.btnSearch.setState = function() {
    this.disable(!(page.testSearch.searchString.value.trim().length > 1));  
}  

thanks

A: 

The code creates a new empty Javascript object called page. Then it adds a property to the object (which in this case turns out to be a function). It looks like it is relying on another function which you haven't pasted in called disable (but I think that we can assume that it disables something in some way!) which will disable something if the text in page.testSearch.searchString is shorter than 1 character long.

It looks to me like it works on a form on a web page.

It must be said that this style of JavaScript coding is a little out-dated, and some might argue that this piece of code would be better written as using object literal notation.

slightlymore
how would you rewrite with object literal..Thanks