开发者

Explaining the setState function

开发者 https://www.devze.com 2022-12-31 08:58 出处:网络
Can someone explain what this function is 开发者_StackOverflow中文版doing var page = new Object();

Can someone explain what this function is 开发者_StackOverflow中文版doing

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消