// once upon a time, there was a princess
var Princess = function() {
// who rode around her world on a unicorn, battled dragons, encountered talking animals, and many other fantastical things.
var unicorn = {
name: 'Sparkles'
};
var dragons = [
'A green one with purple wings',
'A mean black one who breathed fire',
'A fluffy white one that looked like a dog'
];
var talkingAnimals = {
squirrel: "Hello!"
};
// and lived in a wonderful world full of adventures
var adventures = [
'My unicorn ' + unicorn.name + ' had a baby!',
'I fought ' + dragons.length + ' dragons!',
'I met a talking squirrel who said "' + talkingAnimals.squirrel + '"'
];
// but she would always have to return back to her dull world of chores and grown-ups
return {
// and she would often tell them of her latest amazing adventure as a princess
tellStory: function() {
return adventures.pop();
}
};
};
// but all they could see is a little girl
var littleGirl = new Princess();
console.log('I am a', littleGirl);
// telling stories about magic and fantasy
console.log('Little girl says:', littleGirl.tellStory());
console.log('Little girl says:', littleGirl.tellStory());
console.log('Little girl says:', littleGirl.tellStory());
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.