Skip to content

Instantly share code, notes, and snippets.

function f(){
return this.a;
}
var a = {a: 'foo'};
var b = {a: 'bar'};
var x = f.bind(a);
var y = x.bind(b);
// bind 只能绑定一次, 可重复绑定
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
// stop capture
ul.addEventListener('click', function(e) {
if(e.currentTarget === e.target) {
console.log(e.target);
}
});
// stop bubbling
li.addEventListener('click', function(e) {
console.log(e.currentTarget);
function styleHyphenFormat(propertyName) {
function upperToHyphenLower(match) {
return '-' + match.toLowerCase();
}
return propertyName.replace(/[A-Z]/g, upperToHyphenLower);
}
function cssStyle2DomStyle(sName) {
let result = sName.replace(/-\w/g, function (match) {
return match.slice(1).toUpperCase();
// Convert a number to a hexadecimal string with:
hexString = yourNumber.toString(16);
// and reverse the process with:
yourNumber = parseInt(hexString, 16);
// Example
let str = 'Hello World 你好';
str.match(/[\u0256-\uffff]/g)
// (2) ["你", "好"]
@a1exlism
a1exlism / find_common_parent.js
Last active March 17, 2018 15:43
do NOT forget `return`
function commonParentNode(oNode1, oNode2) {
if (oNode1.contains(oNode2)) {
return oNode1;
} else {
return commonParentNode(oNode1.parentNode, oNode2);
}
}
/**
* @param {String} HTML representing a single element
* @return {Element}
*/
function htmlToElement(html) {
var template = document.createElement('template');
html = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = html;
return template.content.firstChild;
}
let body = document.querySelector('body');
let bodyStyle = window.getComputedStyle(body);
Object.prototype.toString.call(bodyStyle);
// "[object CSSStyleDeclaration]"
console.log('body background: ' + bodyStyle.getPropertyValue('background');
body.style.background = '#000';
let x = new Function('a', 'b', 'return a + b');
x(1,2);
// 3