Skip to content

Instantly share code, notes, and snippets.

View st3v3nhunt's full-sized avatar
🖥️
🎧 🎮 👨‍💻

Steve Hunt st3v3nhunt

🖥️
🎧 🎮 👨‍💻
View GitHub Profile
// single quotes over double quotes
// variables
var a, b, c;
var a = 'a',
b = 'b',
c = 'c';
@st3v3nhunt
st3v3nhunt / OO.js
Created March 30, 2011 20:55
OO JavaScript
function Car (doors, fuel, color) {
this.doors = doors;
this.color = color;
this.fuel = fuel;
this.changeFuel = function () {
if (this.fuel === 'petrol') {
this.fuel = 'diesel';
} else {
@st3v3nhunt
st3v3nhunt / json.js
Created March 30, 2011 21:05
JSON JavaScript
Car = {
doors: 0,
fuel: '',
color: '',
changeFuel: function (fuel) {
fuel === 'petrol' ? Car.fuel = 'petrol' : Car.fuel = 'diesel';
}
};
Car.changeColor = function (color) {
@st3v3nhunt
st3v3nhunt / equals.js
Created May 8, 2011 22:05
JS equality operator
1 == '1'; // true
1 === '1'; // false
1 === 1; //true
@st3v3nhunt
st3v3nhunt / iterator-caching.js
Created May 10, 2011 19:22
JS for iterator caching
// no caching of iteration size
for (var i=0; i<myArray.length; i++) {}
// caching of iteration size - ugly version
var length = myArray.length;
for (var i=0; i<length; i++) {}
// caching of iteration size - nice version
for (var i=0, len=myArray.length, i< len; i++) {}
@st3v3nhunt
st3v3nhunt / parseInt.js
Created May 11, 2011 18:49
parseInt with radix
// returns 9
parseInt('09', 10);
// returns 0!
parseInt('09');
@st3v3nhunt
st3v3nhunt / long-array-iteration.js
Created August 8, 2011 21:55
Long way to iterate over an array
var arr = [1,2], i=0, len=arr.length;
for (; i<len; i++) {
console.log('printing: ' + arr[i]);
}
@st3v3nhunt
st3v3nhunt / forEach-iteration.js
Created August 8, 2011 21:57
Using forEach to iterate over an array
[1,2].forEach(function (a, b, c) {
console.log('printing: ' + a);
});
@st3v3nhunt
st3v3nhunt / 0_reuse_code.js
Created April 24, 2014 06:39
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console