This snippet comes to mind from time to time – one easy way to divide a rectangle into smaller rectangles- I actually went back and looked it up as it was an answer to a student question from 2006. The original one was written in ActionScript 2. Have a look:
var wormNum:Number=123;
var wormCount:Number=0;
newWorm(400,400,0,0);
this.onEnterFrame=function(){
if(wormCount < wormNum){
for(var props:Stringinthis){
if(this[props]._x !=undefined){
this[props].divide();
}
}
}
};
function newWorm(w, h, xp, yp){
var currWorm:MovieClip =this.createEmptyMovieClip("box"+wormCount,this.getNextHighestDepth());
In vanilla js you’ll find yourself checking if an HTML DOM element can be removed, by seeing if it has a parent (as seen above). Forgetting to do so is the source of many errors.
With the death of IE11 you can use remove()
const button = document.createElement('button');
button.innerText='Hello There 2';
document.body.appendChild(button);
// click anywhere
document.body.addEventListener('click',()=>{
button.remove();
});
No error occurs when calling remove() on something that is already removed… just like the old jQuery days 😉
Very nice inverse function calculator by user fawad over at Wolfram Alpha. Was attempting to invert a standard “exponential in” easing function – after some futzing I resorted to the calculator 😀