Skip to content

Instantly share code, notes, and snippets.

View PeterRao's full-sized avatar

Undefined PeterRao

  • 北京
View GitHub Profile
@PeterRao
PeterRao / .jshintrc
Created March 3, 2014 03:04
JSHint 文件
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 100, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
@PeterRao
PeterRao / first.js
Created March 27, 2014 10:46 — forked from sofish/first.js
// 大家写在评论中吧,代码高亮可以这样写:
// ```js
// your code
// ```
// update: Fri Aug 31 08:39:21
// copyright: https://gist.github.com/3549352
// 加个性能测试:http://jsperf.com/get-dom-s-first-element
var util = {};

This Is Absolutely Tiring

Every time I start a node module, or a new JS project, I'm confronted with this same question: how do I structure it to allow it to be used in the browser or nodejs, without requiring a build step, and without getting in the way of my development?

While developing, I typically create some type of [browser-based environment][]; Firebug and Web Inspector are still miles ahead of anything else we've got. Ideally I want to be able to add a file via a script tag, and have that be the only requirement.

As @visionmedia [points out][], this is [ridiculous][].

This gist is meant to compile all of the various ways I've seen of guarding against/for a variety of module systems. Fork it and add your own, I'll try to bring them into this one.

@PeterRao
PeterRao / judgeINIframe
Last active August 29, 2015 14:05
How to judge whether 1 JS in iframe(http://www.programering.com/a/MDOwMzMwATg.html)
//One way
if (self.frameElement && self.frameElement.tagName == "IFRAME") {
alert('In iframe');
}
//Methods two
if (window.frames.length != parent.frames.length) {
alert('In iframe');
}
//Fang Shisan
if (self != top) {
@PeterRao
PeterRao / urlparser.js
Last active August 29, 2015 14:11 — forked from sofish/urlparser.js
var parser = function(url) {
var a = document.createElement('a');
a.href = url;
var search = function(search) {
if(!search) return {};
var ret = {};
search = search.slice(1).split('&');
for(var i = 0, arr; i < search.length; i++) {
@PeterRao
PeterRao / pub-sub.js
Last active February 1, 2016 12:07
发布订阅模式,支持事件先发布
var Event = (function() {
var global = this,
Event,
_default = 'default';
Event = function() {
var _listen,
_trigger,
_remove,
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Virtual Template Example</title>
</head>
<body>
</body>
var serialAsyncMap = function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(collection, fn) {
var result, _iterator, _isArray, _i, _ref2, item;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
result = [];
_iterator = collection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();