有人可以向我解释这段代码的用途吗?javascript代码说明
dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");
下面是此函数值所属的功能:
// Provide the class
dojo.provide("tweetview._ViewMixin");
// Declare the class
dojo.declare("tweetview._ViewMixin", null, {
// Returns this pane's list
getListNode: function() {
return this.getElements("tweetviewList",this.domNode)[0];
},
// Updates the list widget's state
showListNode: function(show) {
dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");
},
// Pushes data into a template - primitive
substitute: function(template,obj) {
return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g, function(match,key){
return obj[key];
});
},
// Get elements by CSS class name
getElements: function(cssClass,rootNode) {
return (rootNode || dojo.body()).getElementsByClassName(cssClass);
}
});
来源:http://dojotoolkit.org/documentation/tutorials/1.6/mobile/tweetview/starting_tweetview
我不明白为什么这个答案得到了否决票。人们可以争辩说,如果'show'是真的,那么不是很多,但是如果'show'是一个真值(即非0,“”,false,null,undefined或NaN),那么它就更多了,但这是一个小小的挑剔。 –
谢谢您再次提出我的答案。 +1为您提供有关真实价值的信息!但是假,“”,null,undefined,0和NaN当然是错误的而不是真正的值!猜猜你把它混合起来:)和-10,20,真,“foobar”,一个对象,一个数组,函数是真正的值。 – japrescott
我开始使用“不”来表示我的列表,以暗示我的意思是除我列出的那些以外的任何价值。我会争辩说,我没有把它混在一起,我的'不'就是错过了。 :) –