Skip to content

Instantly share code, notes, and snippets.

View elrrrrrrr's full-sized avatar
🐼
Hope it was happy

elrrrrrrr elrrrrrrr

🐼
Hope it was happy
  • alipay.com
  • Shanghai
View GitHub Profile
@elrrrrrrr
elrrrrrrr / Hoisting
Last active August 29, 2015 14:05
javascript
var v='Hello World';
(function(){
alert(v);
var v='I love you';
})()
var v='Hello World';
(function(){
var v;
alert(v);
@elrrrrrrr
elrrrrrrr / 处理条件判断
Created August 10, 2014 05:04
Jade gist in huiyin
//jade 通过缩进行条件判断,所以需要使用三元表达式进行简单的class添加
ul.ul-con(class=isAdd?'add':'disadd')
@elrrrrrrr
elrrrrrrr / js in brower
Created August 12, 2014 13:26
localstroge hotfix by sofish
// 解决隐私模式下 localStorage 不正常问题
;(function() {
var KEY = '_localStorage_'
, VALUE = 'test';
// 检测是否正常
try {
localStorage.setItem(KEY, VALUE);
} catch(e) {
var noop = function() {};
@elrrrrrrr
elrrrrrrr / 加载
Created August 15, 2014 06:15
加载node模块
var mod = require('module');
module.exports = function module_exist(name){
/**
* This is UGLY but since we're not allowed to require 'native_module'
* this is the only way to test if a native module (or non-native module) exist.
*/
try{
require(name);
} catch(err){
@elrrrrrrr
elrrrrrrr / hover 菜单
Created August 17, 2014 08:51
HTML 组件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Show Hide Dropdown Using CSS</title>
<style type="text/css">
ul{
padding: 0;
list-style: none;
}
@elrrrrrrr
elrrrrrrr / JS Event
Created August 18, 2014 07:20
添加事件监听
function addListener(target, type, handler) {
if (target.addEventListener) {
target.addEventListener(type, handler, false)
} else if (target.attachEvent) {
target.attachEvent("on" + type , handler);
} else {
target["on" + type] = handler;
}
}
@elrrrrrrr
elrrrrrrr / async load template
Created August 18, 2014 07:30
异步加载模版
function loadDialog(name, oncomplete) {
var xhr = new XMLHttpRequest();
xhr.open("get", "/js/dialog/" + name, true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200){
var div = document.getElementById("dlg-holder");
div.innerHTML = xhr.responseText;
oncomplete();
@elrrrrrrr
elrrrrrrr / get the type of reference type
Last active August 29, 2015 14:05
判断JS引用对象类型
function getType(foo, type) {
return Object.prototype.toString.call(foo) == "[Object " + type + "]"
}
//ES5 Array 有isArray方法
function isArray(value) {
if (typeof Array.isArray === "function") {
return Arrary.isArray(value);
} else {
@elrrrrrrr
elrrrrrrr / hasProperty
Created August 18, 2014 08:44
js对象属性检测
// 好的写法
if ('count' in object)
//判断DOM对象 IE8之前 DOM对象不从Object对象继承 需要判断
//判断实例需要使用hasOwnProperty
if (object.hasOwnProperty("related")) {
//非dom对象
}
@elrrrrrrr
elrrrrrrr / MyError
Created August 18, 2014 08:59
自定义错误类型
function MyError(code, message) {
this.code = code;
this.message = message;
}
MyError.prototype = new Error();