奇怪的结构?

发布于 2024-12-08 08:04:52 字数 531 浏览 0 评论 0原文

这行js代码的含义是什么:

        ('selectionchange',function(sm, rs) {
            if (rs.length) {
                var detailPanel = Ext.getCmp('detailPanel');
                bookTpl.overwrite(detailPanel.body, rs[0].data);
            }
        })

这是以下链接的一部分: http://dev.sencha.com /deploy/ext-4.0.2a/examples/grid/binding-with-classes.js


更新: 我删除了这些行并且代码运行没有任何差异! 这是一个编码错误 谢谢大家

What dose this lines of js code means:

        ('selectionchange',function(sm, rs) {
            if (rs.length) {
                var detailPanel = Ext.getCmp('detailPanel');
                bookTpl.overwrite(detailPanel.body, rs[0].data);
            }
        })

this is a part of below link:
http://dev.sencha.com/deploy/ext-4.0.2a/examples/grid/binding-with-classes.js


Update:
I removed these lines and code runs without any diffrenece!
It's a coding mistake
Thanks all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无语# 2024-12-15 08:04:52

我会冒险称其为编辑错误。这里有更多背景信息:

    initEvents: function() {
        // call the superclass's initEvents implementation
        this.callParent();

        // now add application specific events
        // notice we use the selectionmodel's rowselect event rather
        // than a click event from the grid to provide key navigation
        // as well as mouse navigation
        var bookGridSm = this.getComponent('gridPanel').getSelectionModel();
        ('selectionchange', function(sm, rs) {
        if (rs.length) {
            var detailPanel = Ext.getCmp('detailPanel');
            bookTpl.overwrite(detailPanel.body, rs[0].data);
        }
    })
        bookGridSm.on('selectionchange', this.onRowSelect, this);
    },

这是整个文件中唯一提到 bookTpl 的内容。有人将看似事件绑定的内容复制到粘贴缓冲区中,并意外地将其粘贴到此文件中,或者故意粘贴它来检查 bookGridSm.on 调用的语法,但在粘贴后忘记清理他们自己。

查找示例的勘误表。

I'll go out on a limb and call it an editing mistake. Here's a little more context:

    initEvents: function() {
        // call the superclass's initEvents implementation
        this.callParent();

        // now add application specific events
        // notice we use the selectionmodel's rowselect event rather
        // than a click event from the grid to provide key navigation
        // as well as mouse navigation
        var bookGridSm = this.getComponent('gridPanel').getSelectionModel();
        ('selectionchange', function(sm, rs) {
        if (rs.length) {
            var detailPanel = Ext.getCmp('detailPanel');
            bookTpl.overwrite(detailPanel.body, rs[0].data);
        }
    })
        bookGridSm.on('selectionchange', this.onRowSelect, this);
    },

That is the only mention of bookTpl in the whole file. Someone copied what appears to be an event binding into their paste buffer and accidentally pasted it into this file or they pasted it in on purpose to check the syntax for the bookGridSm.on call and forgot to clean up after themselves.

Look for an errata list for the examples.

没企图 2024-12-15 08:04:52

这段代码本身不执行任何操作,它只是死代码,是使用逗号运算符的括号表达式。

逗号运算符将计算第一个表达式 'selectionchange' ,然后计算函数表达式,但完全没有效果,事实上,进行优化的 Javascript 引擎甚至可能不会计算这两个表达式。

看起来像一个函数调用(可能是bookGridSm.on方法,以绑定事件处理程序,因为该对象是函数范围内的唯一对象),但不知何故它们删除了调用函数 whey 的引用。

The piece of code by itself doesn't do anything, it's just dead code, a parentethized expression that uses the comma operator.

The comma operator will evaluate the first expression 'selectionchange' and then the function expression, but with absolutely no effect, in fact, a Javascript engine that does optimization might not even evaluate these two expressions.

Looks like a function call (probably to the bookGridSm.on method, to bind an event handler, since that object is the only on scope of the function) but somehow they removed the reference of the function whey where calling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文