javascript代码说明(javascript code explanation)

有人可以向我解释这段代码的作用吗?

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

Can someone explain to me what this code does?

dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");

Here's the function in which this function value belongs to:

// 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);     } });

Source: http://dojotoolkit.org/documentation/tutorials/1.6/mobile/tweetview/starting_tweetview

最满意答案

很简单,如果show为true,它将调用dojo.removeClass(this.listNode, "tweetviewHidden"); 如果是false,它将调用dojo.addClass(this.listNode, "tweetviewHidden"); 。 基本上它是一个切换功能。

[]括号打开一个对象以按键访问该值。 就像var bla={"foo":"bar"}; bla["foo"]; var bla={"foo":"bar"}; bla["foo"]; 。 现在,由于它的dojo,值是一个函数,将被执行

quite simple, if show is true, it will call dojo.removeClass(this.listNode, "tweetviewHidden"); and if its false, it will call dojo.addClass(this.listNode, "tweetviewHidden");. Essentially its a toggling function.

the [ ] brackets open up an object to access the value by key. just like var bla={"foo":"bar"}; bla["foo"];. Now, since its dojo, the value is a function, which will be executed

javascript代码说明(javascript code explanation)

有人可以向我解释这段代码的作用吗?

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

Can someone explain to me what this code does?

dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");

Here's the function in which this function value belongs to:

// 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);     } });

Source: http://dojotoolkit.org/documentation/tutorials/1.6/mobile/tweetview/starting_tweetview

最满意答案

很简单,如果show为true,它将调用dojo.removeClass(this.listNode, "tweetviewHidden"); 如果是false,它将调用dojo.addClass(this.listNode, "tweetviewHidden"); 。 基本上它是一个切换功能。

[]括号打开一个对象以按键访问该值。 就像var bla={"foo":"bar"}; bla["foo"]; var bla={"foo":"bar"}; bla["foo"]; 。 现在,由于它的dojo,值是一个函数,将被执行

quite simple, if show is true, it will call dojo.removeClass(this.listNode, "tweetviewHidden"); and if its false, it will call dojo.addClass(this.listNode, "tweetviewHidden");. Essentially its a toggling function.

the [ ] brackets open up an object to access the value by key. just like var bla={"foo":"bar"}; bla["foo"];. Now, since its dojo, the value is a function, which will be executed