Skip to content

Instantly share code, notes, and snippets.

View MikeDigitize's full-sized avatar
👋
Howdy

Mike Chadwick MikeDigitize

👋
Howdy
View GitHub Profile
@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'>
/*
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
/*
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();
function makeNull(a) {
a = null;
console.log('makeNull?', a);
}
var obj = { a: 1 };
makeNull(obj);
console.log('null?', obj);
var str = 'mike';
makeNull(str);
function prop(obj) {
return function(prop) {
return obj[prop];
}
}
/* Create a Stack constructor that
- creates an object that stores strings within a single string
- that has a way of delimiting strings
- has a push, pop, concat method that works exactly like their array counterparts
- has an indexesOf method that behaves just like Array.prototype.indexOf but will also find all indexes if more than one exist
- does your constructor initialise with a single string or an array of strings?
- does it have to be called as a constructor / class - could it just be an object / function?
*/
/* Modify the below to create a new builder constructor pattern
Give Video a static property called `make` - an object - that creates the following API:
Video.make
.setSrc('/videos/video.mpeg')
.setTitle('AO Video')
.setLoop(true);
which returns a new instance of Video
/* Array.prototype.fill
Can only modify an array that has a length of at least 1
It changes ALL the values of an array to a single value.
Make a betterFill method that fills an empty array
And takes a first argument which is the length of the array
And a second which is the values to insert
The second should be either a single value or an array of values
/* without making `counter` a global variable refactor callMe
so the recursion it's attempting works correctly
and it logs 'Finished' when complete
var callMe = function() {
const counter = 0;
if(counter == '10') {
console.log('Finished');
}
counter++;
// choose an attribute style
const AwesomeComponent = ({ onAwesomeHappening }) => (
<div className={`${styles.awesomeHolder}`}>
<span
data-mode="awesome-mode"
data-tagging="awesome-btn-click"
className={`${styles.awesomeBtn}`}
onClick={ () => onAwesomeHappening('Awesome!') }>
Save
</span>