function add(x) {
var i = 0;
return function() {
i = i + 1;
//console.log("value of x"+x);
//console.log("value of y"+y);
//console.log(i*x);
}
}
var addo = new add(2);
addo();
//setInterval(addo,1000);
//setTimeout(addo,10000);
(function check() {
a();
//b();
console.log(i)
var i = 7;
console.log(i)
//this is compile time function
function a() {
console.log("hi");
}
//this is a runtime function
var b = function() {
console.log(" From B hi");
}
})()
//Design pattern in Js
function click() {
alert("clicked");
//event= event || window.event;
//var target= event.target || event.srcElement;
//alert(target.id + target.tagName);
}
//Modular approach
var meth = (function() {
var onj = {};
onj.getName = function() {
console.log("hi");
}
return onj;
})();
meth.getName();
//Revealing modular approach
var meth2 = (function() {
var getName = function() {
console.log("hi from second");
}
var getID = function() {
console.log("hi from id")
}
return {
first: getName,
second: getID
}
})();
meth2.first();
//Singleton pattern
var single = (function() {
var instance;
var find = function() {
console.log("Hi from singleton");
}
return {
findmethod: function() {
if (!instance) {
instance = new find();
}
return instance;
}
}
})()
//ins1=single.findmethod();
ins2 = single.findmethod();
//alert(ins1===ins2);
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.