Skip to content

Instantly share code, notes, and snippets.

@StuPig
StuPig / study-on-JS-Class&JS-prototype-inheritence.js
Created May 11, 2012 09:38
探究JavaScript类的属性(property)、原型继承(prototype inheritence)、和构造器(constructor)
// 先定义一个Person类
var Person = function (name, age) {
this.name = name;
this.age = age;
this.tmp = 'this.tmp';
this.sayName = function() {
console.log('this.sayName(): ', this.name);
}
}
@StuPig
StuPig / escaped.js
Created September 20, 2012 03:54
string escaped ( copied from YUI library )
/**
Returns a copy of the specified string with special regular expression
characters escaped, allowing the string to be used safely inside a regex.
The following characters, and all whitespace characters, are escaped:
- $ ^ * ( ) + [ ] { } | \ , . ?
If _string_ is not already a string, it will be coerced to a string.
@method regex
@StuPig
StuPig / dabblet.html
Created September 20, 2012 04:23
Untitled
<!-- content to be placed inside <body>…</body> -->
@StuPig
StuPig / handlebars_JSON_value_as_key_helper.js
Created October 24, 2012 12:47
manipulate JSON's value as key with Handlebars' helper
var source ='\
{{#each types.type}}\
<h2>{{this}}</h2>\
<p>{{#test ../this }}{{/test}}</p>\
{{/each}}\
'
var data = {
types: {
type: [
'o', 'k'
@StuPig
StuPig / mkdir_p.js
Created October 31, 2012 07:14 — forked from hongru/mkdir_p.js
mkdir -p for node
/* mkdir -p for node */
var fs = require('fs'),
path = require('path');
function mkdirpSync (pathes, mode) {
mode = mode || 0777;
var dirs = pathes.trim().split('/');
if (dirs[0] == '.') {
// ./aaa
dirs.shift();
@StuPig
StuPig / build.js
Created October 31, 2012 10:50 — forked from millermedeiros/build.js
sample node.js build script including RequireJS optimizer (r.js) and copy/delete/filter files
// Combine JS and CSS files
// ---
//
// Make sure you install the npm dependencies
// > cd YOUR_PROJECT_FOLDER
// > npm install
//
// Than run:
// > node build
@StuPig
StuPig / gist-slide
Last active December 10, 2015 17:08
!SLIDE
# 前端组2012Q4工作总结 - 巩守强
!SLIDE
##
[Picture Show ためしてみたお( ^ω^) ](http://d.hatena.ne.jp/xuwei/20110903/1315044919)
@StuPig
StuPig / detectLocalStorage.js
Created July 19, 2013 07:25
detect and use localStorage
// Feature detect + local reference
var storage,
fail,
uid;
try {
uid = new Date;
(storage = window.localStorage).setItem(uid, uid);
fail = storage.getItem(uid) != uid;
storage.removeItem(uid);
fail && (storage = false);
@StuPig
StuPig / require.cache.js
Last active December 20, 2015 01:59
use ajax to load script
define(['module'], function (module) {
'use strict';
var storage = (function(){
var uid = new Date,
result;
try {
localStorage.setItem(uid, uid);
result = localStorage.getItem(uid) == uid;
localStorage.removeItem(uid);
@StuPig
StuPig / throttle.js
Created August 28, 2013 02:42
js方法执行频次限制(时间)
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};