This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function can be used to check the sanity of variables | |
* | |
* @access private | |
* | |
* @param string $type The type of variable can be bool, float, numeric, string, array, or object | |
* @param string $string The variable name you would like to check | |
* @param string $length The maximum length of the variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach(get_class_methods(new ArrayObject()) as $key=>$method) | |
{ | |
echo $key.' -> '.$method.'<br />'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple way to avoid running code again when user click a button or trigger event in some other way | |
var shutdown = function() { | |
shutdown = function() { | |
alert("don't worry - we're already processing your shutdown request"); | |
} | |
alert('This runs first!'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getMyText = function(myDiv) { | |
getMyText = | |
myDiv.innerText !== undefined ? // innerText not supported in FF | |
function(myDiv) {return myDiv.innerText} : | |
function(myDiv) {return myDiv.textContent}; | |
return getMyText(myDiv); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Foo(n) { | |
this.Name = n; | |
} | |
$.extend( Foo.prototype, new jQuery.Interface, { // more prototype methods } ); | |
// Foo preserves .constructor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.extend($.expr[':'],{ | |
inline: function(a) { | |
return $(a).css('display') === 'inline'; | |
} | |
}); | |
// $(':inline'); // Selects ALL inline elements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows you to pass a function to jQuery's 'css' method | |
// This means you can use the -this- keyword to reference | |
// the current element!!! | |
(function($){ | |
$.fn.oldCSSMethod = $.fn.css; | |
$.fn.css = function(o) { | |
return $.isFunction(o) ? | |
$(this).each(function(){ | |
$(this).oldCSSMethod(o.call(this)); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Defination: | |
Inner functions referring to local variables of its outer function create closures | |
OR | |
Declaring a function within another function, and that inner function has access to its parent function's variables, even after that parent function has returned. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple way to convert an object to an array with all butter of array using Array.slice | |
function foo(a, b, c){ | |
var argsArray = [].slice.apply(arguments); | |
argsArray.push(4,5); | |
alert(argsArray[4]); //5 | |
} | |
foo(1, 2, 3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function format(string) { | |
var args = arguments; | |
var pattern = RegExp("%([1-" + (arguments.length-1) + "])", "g"); | |
return string.replace(pattern, function(match, index) { | |
return args[index]; | |
}); | |
}; | |
format("a %1 and a %2", "cat", "dog"); | |
//"a cat and a dog" |