Skip to content

Instantly share code, notes, and snippets.

View flipflop's full-sized avatar

Rozario Chivers flipflop

View GitHub Profile
@flipflop
flipflop / gist:1240536
Created September 25, 2011 11:58
JavaScript Closure to correct lost scope
<ul>
<li>item One</li>
<li>item Two</li>
<li>item Three</li>
</ul>
<script>
var listElements = document.getElementsByTagName("li");
@flipflop
flipflop / gist:1240523
Created September 25, 2011 11:37
JavaScript Multi-line String Concatenation
// old way
var myOldString = "some really long text repeated" +
some really long text repeated" +
some really long text repeated";
// Potentially better for Performance and Memory usage
var myString = "some really long text repeated\n\
some really long text repeated\n\
@flipflop
flipflop / Javascript Buffered String (kinda)
Last active September 27, 2015 08:27
String Concatenation in JavaScript
// old concatenation (creates a new variable in memory for each +)
var stuckTogetherOld = "value1" + "value2" + "value3";
// Better:
// Front End Performance Tip for string concatenation or JS Templates
var stuckTogether = ["value1", "value2", "value3"].join("");
// Quicker to execute
var tmpl = ''.concat(
@flipflop
flipflop / getClassNameByIndex
Created September 25, 2011 11:30
Get a class name from multiples
<div id="main" class="style1 style2 style3">
</div>
<script>
console.log(main.className.split(" ")[0]); // first className
console.log(main.className.split(" ")[1]); // second className
console.log(main.className.split(" ")[2]); // third className