javascript代码说明(javascript code explanation)

编程入门 行业动态 更新时间:2024-10-23 04:58:59
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

更多推荐

本文发布于:2023-08-07 21:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   javascript   explanation   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!