Skip to content

Instantly share code, notes, and snippets.

@jsmaker
jsmaker / BaseClass.js
Created November 11, 2012 00:56
BaseClass
function BaseClass(name, methods, statics){
var $$$ = 'function $$$(args) {'+
'args = arguments;'+
'if(!(this instanceof $$$)){ return new $$$($$$, arguments) }'+
'if(args[0] === $$$){ args = args[1] }'+
'if(this.init){ return this.init.apply(this, args) }'+
'}';
var _Class = ConstructorWithName(name);
@jsmaker
jsmaker / defined.js
Created November 2, 2012 03:16
defined.js fast and small AMD loader
var defined = function (setup) {
'use strict';
setup.symble = setup.symble || 'define';
/////////////healpers//////////////
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
[].filter ||(Array.prototype.filter = function(fn, thisp) { if (this === null) throw new TypeError; if (typeof fn !== "function") throw new TypeError; var result = []; for (var i = 0; i < this.length; i++){if (i in this) {var val = this[i]; if (fn.call(thisp, val, i, this)){result.push(val);}}} return result;});
[].map||(Array.prototype.map=function(a){for(var b=this,c=b.length,d=[],e=0,f;e<b;)d[e]=e in b?a.call(arguments[1],b[e],e++,b):f;return d});
var xmlHTTPObject = (function getXMLHTTPObject(){var e=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],t=!1;for(va
@jsmaker
jsmaker / gist:3997730
Created November 2, 2012 00:02
style from doc
var map = [].map;
var styles = map.call(document.styleSheets,function(sheet){
return map.call(sheet.cssRules,function(rule){
return rule.cssText;
});
});
styles = map.call(styles,function(s){
return s.join('\n');
}).join('\n\n');
@jsmaker
jsmaker / Demo1
Created September 14, 2012 01:33
Some nice Lisp concepts is Javascript
Jsl()
( 'sum', 1, 2)
( Jsl.get, function(val){ this.firstSum = val; } )
( Jsl.sum, 1, 2, 3, 4, 5 )
( Jsl.mul, 1, 2, 3, 4, 5 )
( Jsl.getAll, function(val1, val2) {
Jsl(this)
( Jsl.set, {secondSum : val1, thirdSum: val2} )
();
@jsmaker
jsmaker / viewTest.js
Created June 28, 2012 10:24
some inheritance tests on view object
//Element.prototype.__appendChild = Element.prototype.appendChild;
//Element.prototype.appendChild = function(){Element.prototype.__appendChild.apply(this, arguments); this.classList.contains('view') && console.log.apply(console, arguments)};
var BObject = function BObject() {};
BObject.$super = function (fn, args, name, parent) {
parent = parent || this.parent();
debugger;
if (parent) {
if (parent.name === name && parent.prototype[fn]) {
@jsmaker
jsmaker / fileSys.js
Created June 28, 2012 08:51
Just playing with the fileSystem Api
;var Fs = (function () {
'use strict';
function extend(obj) {
Array.prototype.slice.call(arguments, 1).forEach(function (source) {
var prop;
for (prop in source) {
if (source[prop] !== void 0) {
obj[prop] = source[prop];
}
}
@jsmaker
jsmaker / Elm.js
Created June 28, 2012 08:47
Generic Collection generator (work in progress)
function Elm(node) {
if (typeof node === 'string') {
node = document.querySelector(node);
}
this.node = node; //|| document.createElement('div');
@jsmaker
jsmaker / toCode.js
Created June 27, 2012 13:02
toCode returns the object as code string
function toCode(o, name) {
name = name || 'code';
var cache = [o];
var toCode = function (o, name) {
if (typeof o === 'string') {
return "'" + o + "'";
}
if (o instanceof Array) {
return toCode.arrayToCode(o, name);
}