Skip to content

Instantly share code, notes, and snippets.

View npup's full-sized avatar
💭
transpiling

P. Envall npup

💭
transpiling
View GitHub Profile
@npup
npup / gist:563727
Created September 3, 2010 10:38
Exploring some ways of fixing when ppl call a constructor function and forgetting a needed "new" operator.
(function (global, ns) {
// Awesome model
function Apa(name, dryg) {
// try to fix if "new" wasn't used
if (!(this instanceof arguments.callee)) {
console.log('No "new" operator used when creating Apa "%s". Fixing..', name);
// v1
//return newFix1(arguments);
// v2
@npup
npup / svin.js
Created December 21, 2010 15:26
Svin, VildSvin och Stior
/** -----------------------------------------------------
* Djur
*
*/
function Svin(name) {
this.name = name;
this.type = 'Svin';
}
Svin.toString = function () {
@npup
npup / var-scope.js
Created December 21, 2010 15:52
Variabler i scope
function apa1() {
var david = 'david';
console.log('%s', david);
}
apa1(); // david
function apa2() {
var david = 'david';
console.log('%s, %s', david, petter);
@npup
npup / spartan placeholder shim
Created October 31, 2013 14:21
Spartan "placeholder" functionality for IE8-9 Works on text inputs only. Uses querySelectorAll, so IE8+ Usage: include <script src="placeholder.js" data-placeholderjs-color="#a8a8a8"></script> at the bottom of a page (color attribute is optional)
/**
*
* @author petter.envall@gmail.com
* @date October 2013
*
* Spartan "placeholder" functionality for IE8-9
*
* Works on text inputs only. Uses querySelectorAll, so IE8+
*
* Usage:
@npup
npup / elem-fac-doc-pender
Created October 31, 2013 14:30
Minimal element factory and DOM appender
var E = (function () {
var global = this, doc = global.document;
function isArray(obj) {return "[object Array]"=={}.toString.call(obj);}
return {
"create": function (tag, attrs) {
var elem = doc.createElement(tag);
for (var attr in attrs) {
if ("html" == attr) {elem.innerHTML = attrs.html;}
else if ("class" == attr) {elem.className = attr;}
else {elem.setAttribute(attr, attrs[attr]);}

Keybase proof

I hereby claim:

  • I am npup on github.
  • I am npup (https://keybase.io/npup) on keybase.
  • I have a public key whose fingerprint is D7C6 C761 93DF EBA1 246C 0EBC 875A 13C2 AE6E BB92

To claim this, I am signing this object:

{"apa": true, "idx": 42}