在看js编程风格的时候,遇到了一个比较常见的问题:
使用 Array#slice 将类数组对象转换成数组。
function trigger() {
var args = Array.prototype.slice.call(arguments);
...
}在看js编程风格的时候,遇到了一个比较常见的问题:
使用 Array#slice 将类数组对象转换成数组。
function trigger() {
var args = Array.prototype.slice.call(arguments);
...
}在看Javascript 秘密花园的时候,发现一段晦涩难懂的代码片段,由于 中文版的没有讲到这个技巧的妙处,所以硬着头皮,看看英文版
Another trick is to use both
callandapplytogether to turn methods - functions that use the value of this as well as their arguments - into normal functions which only use their arguments.
(大概的意思是:可以一起使用call和apply将使用this和参数的方法函数转化为使用相同参数的普通函数),
这不是在普通函数中利用call和apply,绑定传入的上下文吗?嗯...挺类似的,但是它两个一起使用,因为上下文是一个函数,需要再利用一次。
全部代码如下
| 在跟着视频一起阅读jQuery的2.0.3源码的时候,发现一个'有意思'的地方,或者说巧妙的地方。 | |
| css()等方法是在jQuery原型属性`prototype`的下面定义的,比如jQuery.prototype.css = function(){//do sth.} | |
| 但是,我们在调用css()方法的时候,首先使用`$()`[也就是`jQuery()`]获取到一个元素对象,从而调用,例如`$('#top').css();`。但是在源码当中, | |
| 当调用jQuery()的时候其实拿到的是init()构造函数的实例。而不是jQuery()构造函数的实例。【因为是jQuery()构造函数的实例,才会向上搜素到该实例的原型对象中的css()等方法】 | |
| ```javascript | |
| jQuery = function( selector, context ) { |
| #!/usr/bin/env python | |
| #coding:utf-8 | |
| # Author: Sg4Dylan --<sg4dylan#gmail.com> | |
| # Purpose: A simple script to download video from Bilibili | |
| # Created: 08/07/2016 | |
| import sys | |
| from subprocess import call | |
| def check_and_go(args): |
| <?xml version="1.0"?> | |
| <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> | |
| <!-- /etc/fonts/conf.avail/51-noto-color-emoji.conf --> | |
| <fontconfig> | |
| <selectfont> | |
| <acceptfont> | |
| <pattern> | |
| <patelt name="family"><string>Noto Color Emoji</string></patelt> | |
| </pattern> | |
| </acceptfont> |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| if (!document.querySelectorAll) { | |
| document.querySelectorAll = function (selectors) { | |
| var style = document.createElement('style'), elements = [], element; | |
| document.documentElement.firstChild.appendChild(style); | |
| document._qsa = []; | |
| style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}'; | |
| window.scrollBy(0, 0); | |
| style.parentNode.removeChild(style); |
We have moved: https://github.com/magnetikonline/linuxmicrosoftievirtualmachines
Due to the popularity of this Gist, and the work in keeping it updated via a Gist, all future updates will take place at the above location. Thanks!
| /* | |
| * Minimal classList shim for IE 9 | |
| * By Devon Govett | |
| * MIT LICENSE | |
| */ | |
| if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') { | |
| Object.defineProperty(HTMLElement.prototype, 'classList', { | |
| get: function() { |