[深入react] 4.牛逼闪闪的虚拟DOM

React.createElement嵌套后的结果就是虚拟dom,虚拟dom听着很高端,其实就是一个json,类似:

{
    type:'div',
    props:{
        className:"box"
    },
    children:[
        'hello ' + 'w' + 'orld',
        {
            type:'i'
        }
    ]
}

其实可以不用jsx

var _ = function(){
    return React.createElement.apply(React,arguments);
};
_('div',{
        className:"box"
    },
    'hello ' + 'w' + 'orld',
    _('i', null)
);

也很清楚,最重要的是省了编译库,jslint也可以继续使用了(太重要了)。

posted @ 2016-11-09 17:10  p2world  阅读(125)  评论(0编辑  收藏  举报