/**
* this is a sweet pattern
**/
//assign config var
var timesMe = 35;
//do page initialization
var multiplyMe = (function(number){
return myNewNumber = {
"total": number *= number
};
}(timesMe));
//page ini vars are stored
console.log(multiplyMe.total);
var add1More = function(){
var count =0;
return function(){
console.log('you now have: '+ (count+=1));
}
}
var show = add1More();
//create person constructor
var Person = function(name) {
this.name = name;
};
Person.prototype.getName = function() {
return "hey, you asked for: " + this.name;
}
var chris = new Person('Chris');
console.log(chris);
function Waffle() {
if (!(this instanceof Waffle)) {
return new Waffle();
}
this.tastes = "yummy";
}
var testMe = Waffle();
console.log(testMe);
/*
//error test
function genericErrorHandler() {
return true;
}
try {
// something bad happened, throw an error
var testMe = NaN;
throw {
name: "MyErrorType",
// custom error type
message: "oops",
extra: "This was rather embarrassing",
remedy: genericErrorHandler // who should handle it
};
} catch (e) {
// inform the user
console.log(e.name); // "oops"
console.log(e.message); // "oops"
console.log(e.extra); // "oops"
// gracefully handle the error
e.remedy();
}
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.