开发者

Strange Structure?

开发者 https://www.devze.com 2023-04-10 21:06 出处:网络
What dose this lines of js code means: (\'selectionchange\',function(sm, rs) { if (rs.length) { var detailPanel = Ext.getCmp(\'detailPanel\');

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 开发者_Go百科coding mistake Thanks all


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号