Skip to content

Instantly share code, notes, and snippets.

View BruceWeng's full-sized avatar
🤓
Optimized for Change

Bruce Weng BruceWeng

🤓
Optimized for Change
  • LeanTaaS
  • San Francisco Bay Area
View GitHub Profile
@paulirish
paulirish / what-forces-layout.md
Last active May 20, 2024 06:33
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@davideicardi
davideicardi / diThreeJsViewer.js
Created April 19, 2015 09:18
Angular Js directive that display a three.js model
// usage:
// <di-three-js-viewer three-js-object="device3DModel"></di-three-js-viewer>
app.directive('diThreeJsViewer', [function() {
function createThreeJsCanvas(parentElement, object) {
var width = 400;
var height = 400;
var scene = new THREE.Scene();
@mpj
mpj / classless.md
Last active November 13, 2023 16:34

The future is here: Classless object-oriented programming in JavaScript.

Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.

Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.

I think it's really, really sleek, and this is what it looks like:

function dog(spec) {
@electricg
electricg / LICENSE-MIT
Last active March 27, 2024 20:59
Stopwatch in javascript
Copyright (c) 2010-2015 Giulia Alfonsi <electric.g@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions: