博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongdb选择存储引擎:_选择引擎:从右到左
阅读量:2515 次
发布时间:2019-05-11

本文共 2612 字,大约阅读时间需要 8 分钟。

mongdb选择存储引擎:

One lessor known fact about CSS selectors, querySelectorAll, and JavaScript-based selector engines is that they read your selectors from right to left.  This news hit me as illogical at first, as you'd think that the first element in a selector string like "#myElement a.something .else" would provide a base context, but no:  the ".else" is search for first.  After more thought, searching for the right-most selector piece makes sense, as you instead collect the ".else" elements first (instead of, theoretically, all the elements under "#myElement", then "a.something" elements, and so on) and then look up the chain for matches.  Essentially, you grab all the potential matches and then confirm by walking up the DOM tree, instead of grabbing the parent and look for matches on the way down.

众所周知,关于CSS选择器,querySelectorAll和基于JavaScript的选择器引擎的一个事实是,它们从右到左读取选择器。 这个消息起初使我感到不合逻辑,因为您会认为选择器字符串中的第一个元素(例如“ #myElement a.something .else”)将提供基本上下文,但没有:“。else”是首先搜索。 经过深思熟虑,搜索最右边的选择器很有意义,因为您可以先收集“ .else”元素(而不是理论上收集“ #myElement”下的所有元素,然后收集“ a.something”元素,依此类推),然后在链中查找匹配项。 本质上,您要抓住所有可能的匹配项,然后通过爬上DOM树进行确认,而不是抓住父项并在向下寻找匹配项。

I was recently looking at popular development site and found the following snippet:

最近,我在一个热门的开发网站上查看了以下代码段:

jQuery("#subscribe-main li:nth-child(4)")....

This snippet found the desired elements in 1ms according to FireBug's console.  A millisecond is lightning fast, but if you slightly change the selector code, you get a faster result:

该片段根据FireBug的控制台在1毫秒内找到了所需的元素。 毫秒很快,但是如果稍微更改选择器代码,则会得到更快的结果:

jQuery("li:nth-child(4)", "#subscribe-main");// Could use this as well// jQuery("#subscribe-main").find("li:nth-child(4)")....

The selection code above returns the same elements in 0ms.  A millisecond difference is negligible in one instance, but in a large application, these milliseconds will add up!

上面的选择代码在0ms内返回相同的元素。 在某些情况下,毫秒的差异可以忽略不计,但是在大型应用程序中,这些毫秒相加!

This post simply acts a a reminder that selector composition is important.  Here's a task for you:  go to the sites you've written the JavaScript selectors for and compare your selectors like I have above.  If you aren't familiar with basic selector time testing via the console, here's how you do it:

这篇文章只是提醒人们选择器的组成很重要。 这是您的任务:转到您为JavaScript选择器编写的网站,然后像上面一样比较选择器。 如果您不熟悉通过控制台进行的基本选择器时间测试,请按以下步骤进行:

console.time("someKey");jQuery("#mySelector .more .stuff")...console.timeEnd("someKey");

The console doesn't do better than millisecond precision, but a different result at that precision gets you started in selector enhancement.  Happy selector revising!

控制台的精度并没有比毫秒精度更好,但是以这种精度产生的不同结果使您开始进行选择器增强。 选择器修改愉快!

翻译自:

mongdb选择存储引擎:

转载地址:http://wuvwd.baihongyu.com/

你可能感兴趣的文章
Modem2G/3G/4G/5G:通信领域常见名词缩写释义(VoLTE,CSFB,CA,RAT...)
查看>>
Modem2G/3G/4G/5G:RFFE Driver(射频前端驱动):高通平台GRFC配置方法
查看>>
异常处理:解决安装双系统(windows+Ubuntu)的PC,进入windows系统时出现花屏的问题
查看>>
异常处理:解决Ubuntu用APT指令安装VirtualBox 6.1报错:The following signatures were invalid: BADSIG
查看>>
异常处理:解决 E: 无法获得锁 /var/lib/dpkg/lock - open ;‘E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
查看>>
Android:Ethernet:实现RJ45有线网和USB host无线网卡的静态IP(StaticIpConfiguration)设置上网(附源码)
查看>>
Linux:原因及解法warning: suggest parentheses around assignment used as truth value [-Wparentheses]
查看>>
Linux: C语言使用管道和shell实现自动登录telnet并执行拓扑查询命令
查看>>
Ubuntu:已解决:安装18.04后报错:依赖: libc6-armel-cross (>= 2.27) 但是 2.23-0ubuntu3cross1 已经安装
查看>>
自定义安装linux/Ubuntu版本操作系统/自定义磁盘分区
查看>>
linux/ubuntu下su进入toor用户提示“认证失败”的解决方案
查看>>
在linux/ubuntu系统下安装LNMP环境
查看>>
在linux操作系统下使用github的基本流程
查看>>
linux系统下apt-get指令的使用
查看>>
linux操作系统中ps指令的使用
查看>>
跨平台开发下换行符CRLF和LF的问题
查看>>
PHP开发时路由中GET方法和POST方法的区别
查看>>
禁止空对象属性的直接访问
查看>>
PHP程序中static关键字的使用
查看>>
PHP程序中const关键字的使用
查看>>