Skip to content

Instantly share code, notes, and snippets.

var myAwesomeLibrary = {
_prop1 : '', //private property. should not be accessed externally
prop2 : '' //public property.
};
//public function of the library
myAwesomeLibrary.fn = function(){};
//function meant for internal usage. Should not be called from outside
myAwesomeLibrary._fn2 = function(){};
@lifeinafolder
lifeinafolder / notoperatortrick2.js
Created December 6, 2010 19:46
Character Search in String using !~ operators
var str = 'posterous';
if ( !~str.search('t') ) {
// character 't' not found branch
}
else{
// found branch
}
@lifeinafolder
lifeinafolder / notoperatortrick.js
Created December 6, 2010 19:43
Character Search in String
var str = 'posterous';
if ( str.search('t') >= 0 ) {
// character t found
}
else{
// not found
}
@lifeinafolder
lifeinafolder / understandingcurrying2.js
Created November 16, 2010 21:23
Currying Example 2
//The curry function that we will use.
var _curry = function() {
var args = Array.prototype.slice.call(arguments);
var fn = args.shift();
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments)));
};
};
@lifeinafolder
lifeinafolder / understandingcurrying.js
Created November 16, 2010 19:56
Currying Example 1
var arrayStore = []; //array to store the responses
// callback fn that is to be called after
// each JSONP call is successful
var callback = function(index,response){
arrayStore[index] = response;
};
var position = 0;
while( position < 5 ){
@lifeinafolder
lifeinafolder / beacons.js
Created October 20, 2010 21:15
Image Beacon
var img = new Image();
var data = 'name="John"';
img.onload = function(){
console.log('data successfully sent');
}
img.src = 'YOUR SCRIPT URL HERE' + '?' + data;
<div class="list">List 1</div>
<div class="list">List 2</div>
<div class="list">List 3</div>
<div class="list">List 0</div>
<div class="list">List 4</div>
<div class="list">List 0</div>
<div class="list">List 1</div>
<div class="list">List 2</div>
<div class="list">List 3</div>
<div class="list">List 4</div>
1. elements = document.getElementsByClassName(names); // or:
2. elements = rootElement.getElementsByClassName(names);
var img = new Image();
img.src = 'YOUR URL HERE';
img.onload = function(){
//do something when the image loads
// for instance, you may shove it in the DOM.
var imgDom = document.createElement('IMG');
imgDom.setAttribute('src','YOUR URL HERE');
//some dom element reference - element
element.appendChild(imgDom);
}