Skip to content

Instantly share code, notes, and snippets.

View 6174's full-sized avatar

Marc Chen 6174

View GitHub Profile
@6174
6174 / Random-string
Created July 23, 2013 13:36
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@6174
6174 / avalon-snippets
Last active December 20, 2015 03:19
avalonJS 源码里边的一些有趣片段!
var DONT_ENUM = "propertyIsEnumerable,isPrototypeOf,hasOwnProperty,toLocaleString,toString,valueOf,constructor".split(",");
var class2type = {};
"Boolean Number String Function Array Date RegExp Object Error".replace(rword, function(name) {
class2type["[object " + name + "]"] = name.toLowerCase()
});
//=========================================================================================================//
//=========================================================================================================//
@6174
6174 / ecma262 v5语法补丁
Last active December 20, 2015 03:19
ecma262 v5语法补丁
/*********************************************************************
* ecma262 v5语法补丁 *
**********************************************************************/
//-_- 这个trim 测试, 我是不是要 "xuejia".trim
if (!"司徒正美".trim) {
String.prototype.trim = function() {
return this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, '')
}
}
@6174
6174 / getcurrentScript.js
Last active December 20, 2015 07:29
获取当前正在执行的脚本的路径!
function getCurrentScript(base) {
// 参考 https://github.com/samyk/jiagra/blob/master/jiagra.js
var stack
try {
a.b.c() //强制报错,以便捕获e.stack
} catch (e) { //safari的错误对象只有line,sourceId,sourceURL
stack = e.stack
if (!stack && window.opera) {
//opera 9没有e.stack,但有e.Backtrace,但不能直接取得,需要对e对象转字符串进行抽取
stack = (String(e).match(/of linked script \S+/g) || []).join(" ")
@6174
6174 / Game-main-loop.js
Last active December 20, 2015 09:58
动画主循环!!
// see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// shim layer with setTimeout fallback
(function(){
// chrome shipped without the time arg in m10
var timeundefined = false;
if (window.webkitRequestAnimationFrame){
webkitRequestAnimationFrame(function(time){
timeundefined = (time == undefined);
@6174
6174 / console.memory.js
Created July 30, 2013 12:19
查看chrome内存!
console.memory
//MemoryInfo {jsHeapSizeLimit: 793000000, usedJSHeapSize: 10000000, totalJSHeapSize: 29400000}
profile('a')
//Profile 'a' started.
//undefined
profileEnd('a')
//Profile 'a' finished.
//undefined
console.profiles
@6174
6174 / Klass.js
Created August 3, 2013 11:04
Klass.js 多重继承!
var xuejia = {
/**
* proxy
*/
proxy: function(context, func) {
return function() {
func.apply(context, arguments);
}
},
/**
/*
* Ticker by Grant Skinner. Dec 5, 2010
* Visit http://easeljs.com/ for documentation, updates and examples.
*
*
* Copyright (c) 2010 Grant Skinner
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@6174
6174 / AssetsManager.js
Last active December 20, 2015 14:49
极其简陋的 js 游戏基础frame -----_-----
/**
* @Module CatGameAssetsManager
*
* @Fan-outs: Event, DOM
*/
KISSY.add('fp-dsf/CatGameAssetsManager', function(S, util) {
var CatGameAssetsManager = {};
var imageList = [