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
var v='Hello World'; | |
(function(){ | |
alert(v); | |
var v='I love you'; | |
})() | |
var v='Hello World'; | |
(function(){ | |
var v; | |
alert(v); |
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
//jade 通过缩进行条件判断,所以需要使用三元表达式进行简单的class添加 | |
ul.ul-con(class=isAdd?'add':'disadd') | |
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
// 解决隐私模式下 localStorage 不正常问题 | |
;(function() { | |
var KEY = '_localStorage_' | |
, VALUE = 'test'; | |
// 检测是否正常 | |
try { | |
localStorage.setItem(KEY, VALUE); | |
} catch(e) { | |
var noop = function() {}; |
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
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){ |
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
<!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; | |
} |
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 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; | |
} | |
} |
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 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(); |
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 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 { |
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
// 好的写法 | |
if ('count' in object) | |
//判断DOM对象 IE8之前 DOM对象不从Object对象继承 需要判断 | |
//判断实例需要使用hasOwnProperty | |
if (object.hasOwnProperty("related")) { | |
//非dom对象 | |
} |
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 MyError(code, message) { | |
this.code = code; | |
this.message = message; | |
} | |
MyError.prototype = new Error(); |
OlderNewer