Skip to content

Instantly share code, notes, and snippets.

View MikeDigitize's full-sized avatar
👋
Howdy

Mike Chadwick MikeDigitize

👋
Howdy
View GitHub Profile
function prop(obj) {
return function(prop) {
return obj[prop];
}
}
function makeNull(a) {
a = null;
console.log('makeNull?', a);
}
var obj = { a: 1 };
makeNull(obj);
console.log('null?', obj);
var str = 'mike';
makeNull(str);
/*
var url = '//media.ao.com/cdnbundle/client/4.0.90.0/bundled/BTS/css/MasterStructure.css';
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if(this.readyState === 4 && this.status === 200) {
console.log(this.responseText);
}
};
ajax.open('GET', url, true);
ajax.send();
/*
Check for presence of computing promo blocks (hidden by default)
Check the cookie and search through SKUs to see if any anti-virus or MS office are in basket
If no MS office display add to basket block and initiliase add to basket
or if MS office show added to basket block
If no antivirus display add to basket block and initiliase add to basket
@MikeDigitize
MikeDigitize / Click bubbling capturing
Created October 7, 2016 20:24
How to capture click events on parent elements when multiple listeners are registered without triggering on the wrong parent
<style>
.buy {
margin-bottom: 20px;
}
</style>
<div class='container'>
<div class='mini-basket'>
@MikeDigitize
MikeDigitize / ES2015 Class Mixins
Last active September 7, 2016 12:45
How to bolt on mixins to a base class in ES2015
// combine properties to base prototype
function Combine(target, fns = []) {
let protoCopy = Object.assign(target.prototype);
let extendedProto = (Array.isArray(fns) ? fns : [fns]).reduce((proto, fn) => {
Object.getOwnPropertyNames(fn.prototype).forEach(prop => {
if(!(protoCopy.hasOwnProperty(prop))) {
proto[prop] = fn.prototype[prop];
}
var selector = '#aoFooterSmallPrint';
var addEvent = a => b => c => a.addEventListener(b, c);
var footerText = document.querySelector(selector);
var footerTextEvents = addEvent(footerText);
var footerTextOnClick = footerTextEvents('click');
var footerTextOnMouseOver = footerTextEvents('mouseover');
var log = evt => console.log(evt);
footerTextOnClick(log);
footerTextOnMouseOver(log);
var jQuery = (function() {
function jQuery(selector, context = document) {
return new jQuery.fn.init(selector, context);
}
jQuery.fn = jQuery.prototype ;
jQuery.fn.css = function(prop, value) {
this.pushStack.forEach(el => el.style[prop] = value);
const capitalise = f => replace(/\b[a-z]/g, f => f.toUpperCase());
const lowercaseilise = f => replace(/\b[A-Z]/g, f => f.toLowerCase());
var PubSub = (function() {
let listeners = {};
return {
listeners,
subscribe (evt, fn) {
if(!this.listeners.hasOwnProperty(evt)) {
this.listeners[evt] = [];
}
this.listeners[evt].push(fn);
return () => {