Skip to content

Instantly share code, notes, and snippets.

View Maciek416's full-sized avatar

Maciej Adwent Maciek416

View GitHub Profile
var Something = function(){ };
Something.prototype.someFunc = function(){
if(this==Something.prototype){
console.log("called on prototype");
} else {
console.log("called on instance of Something");
}
};
[{k:"z"},{k:"f"},{k:"a"},{k:"b"}].sort(function(a,b){
return a.k==b.k?0:a.k<b.k?-1:1;
});
// yields :
// [{k:"a"},{k:"b"},{k:"f"},{k:"z"}]
<html>
<head>
<script>
function draw() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var offset = 150;
var radius = 0;
var orbits = 10;
var pi = 3.1415926535897932384626433832795028;
@Maciek416
Maciek416 / gist:938716
Created April 23, 2011 15:46
How to confuse jade.js's with() statement
<html>
<body><div id="test"></div></body>
<script src="jade.js"></script>
<script>
var jade = require("jade");
var template = "h1 #{value}";
var model = {
escape: function(){
@Maciek416
Maciek416 / gist:939591
Created April 24, 2011 14:43
Backbone.Model.escape
escape : function(attr) {
var html;
if (html = this._escapedAttributes[attr]) return html;
var val = this.attributes[attr];
return this._escapedAttributes[attr] = escapeHTML(val == null ? '' : val);
},
@Maciek416
Maciek416 / gist:944501
Created April 27, 2011 15:39
Adding arguments
var f1 = function(){
console.log(arguments);
};
var f2 = function(a,b,c){
var args = [];
for(var i=0;i<arguments.length;i++){
args[i] = arguments[i];
}
args.push("__4__");
\=======\
\\o/=\o/\
\ \=======\ Weeeeeeeeeeeee
\ \\o/=\o/\
\ \=======\
\ \_______\
\/_=___=_/
_\\__\\_
``\\``\\`
_\\__\\_
@Maciek416
Maciek416 / gist:991545
Created May 25, 2011 18:20
Crockford-style Backbone.Model with privates
var Circle = function(options){
var private = {
privateSecretToken: "this is a secret"
};
return new (Backbone.Model.extend({
initialize: function(){
console.log("");
var extend = function (protoProps, classProps) {
var child = inherits(this, protoProps, classProps);
child.extend = extend;
return child;
};
// Set up inheritance for the model, collection, and view.
Backbone.Model.extend = Backbone.Collection.extend = Backbone.Controller.extend = Backbone.View.extend = extend;
@Maciek416
Maciek416 / gist:1002432
Created June 1, 2011 14:43
Attempts to make an object show up as instance_of.JimBobbbbb in console.log
var JimBob = function Barf(x){ this.x = x; };
JimBob.prototype.klass = "JimBobbbbb";
var creator = function(c, args){
var instance_of = {};
instance_of[c.klass] = function(){
return c;
};
return new (instance_of[c.klass].call(this, args));
};