Skip to content

Instantly share code, notes, and snippets.

@ianpgall
ianpgall / string-trim.js
Last active December 20, 2015 00:28
JavaScript function to trim Strings (detects native browser support)
var Trim = (function () {
"use strict";
var S, both, left, right;
S = "";
if (S.trim && !S.hasOwnProperty("trim")) {
both = function (str) {
return S.trim.call(str);
@ianpgall
ianpgall / object-clone.js
Last active December 20, 2015 00:19
JavaScript function that deep clones an Object or Array
var Clone = (function () {
"use strict";
var O, toString,
objType, arrType,
isObject, isArray,
each, iterator;
O = {};
toString = function (p) {
@ianpgall
ianpgall / function-once.js
Last active December 20, 2015 00:19
JavaScript function that allows the execution of a Function once
var Once = (function () {
"use strict";
var A, F, func;
A = [];
F = function () { return undefined; };
func = function (f) {
var ret, ran, retValue;
@ianpgall
ianpgall / function-bind.js
Last active December 20, 2015 00:19
JavaScript function that binds the context of a Function, returning a new one (detects native browser support)
var Bind = (function () {
"use strict";
var A, F, ret;
A = [];
F = function () { return undefined; };
if (F.bind && !F.hasOwnProperty("bind")) {
ret = function (func, thisArg /*, args */) {
@ianpgall
ianpgall / element-dataset.js
Last active December 20, 2015 00:18
JavaScript function to manipulate an Element's dataset/data-* attributes (detects native browser support)
var DataSet = (function () {
"use strict";
var E, toCamelCase, getter, setter;
E = document.createElement("div");
if (E.dataset && !E.hasOwnProperty("dataset")) {
toCamelCase = (function () {
var re = /-([a-z])/g;