有人可以向我解釋這段代碼的用途嗎?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
我開始使用「不」來表示我的列表,以暗示我的意思是除我列出的那些以外的任何價值。我會爭辯說,我沒有把它混在一起,我的'不'就是錯過了。 :) –