// Install n from npm
$ sudo npm install -g n
// Install different version for Node.js
$ sudo n 0.12.0
$ sudo n 0.10.36
// Quickly switch between the Node.js version with the command n
$ n
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 浅复制,子类实例引用类型属性的修改会影响父类对应的属性 | |
*/ | |
function clone(parent, child) { | |
var i; | |
child = child || {}; | |
for(i in parent){ | |
if(parent.hasOwnProperty(i)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(win, doc){ | |
var $ = function(selector) { | |
// 获取元素的方法映射 | |
var matches = { | |
'#': 'getElementById', | |
'.': 'getElementsByClassName', | |
'@': 'getElementsByName', | |
'*': 'getElementsByTagName', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" id="search" name="" autofocus> | |
<script type="text/javascript"> | |
(function(inputField){ | |
// typeof inputField.autofocus === 'boolean' | |
// or !inputField.autofocus | |
if(inputField.autofocus !== true){ | |
inputField.focus(); | |
} | |
})(document.getElementById('search')); |
/Apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "F:/xxx/xxx" <- code
ServerName myhost.example.com
ErrorLog "logs/myhost.example.comm-error.log"
CustomLog "logs/myhost.example.com-access.log" common
function fetchJSON(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = 'json';
xhr.send();
xhr.onload = function() {
if(xhr.response) {
resolve(xhr.response);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
@media (min-device-width:600px) { | |
img[data-src-600px] { | |
content: attr(data-src-600px, url); | |
} | |
} | |
@media (min-device-width:800px) { | |
img[data-src-800px] { | |
content: attr(data-src-800px, url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepClone(target) { | |
if(typeof target !== 'object') { | |
return target; | |
} | |
if(target.constructor === RegExp) { | |
return target; | |
} | |
var result = new target.constructor(); |
NewerOlder