Click here to Skip to main content
15,902,634 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Changing a video at a certain time Pin
ZurdoDev4-Apr-17 0:42
professionalZurdoDev4-Apr-17 0:42 
GeneralRe: Changing a video at a certain time Pin
Citizen Vik4-Apr-17 7:47
Citizen Vik4-Apr-17 7:47 
GeneralRe: Changing a video at a certain time Pin
ZurdoDev4-Apr-17 7:49
professionalZurdoDev4-Apr-17 7:49 
GeneralRe: Changing a video at a certain time Pin
Citizen Vik4-Apr-17 9:34
Citizen Vik4-Apr-17 9:34 
QuestionHow I can add methods to add or get values in a dictionary object ? Pin
Izis30-Mar-17 0:57
Izis30-Mar-17 0:57 
QuestionNode js Reading HTML page Pin
Member 1304854330-Mar-17 0:31
Member 1304854330-Mar-17 0:31 
QuestionHow to implement a custom javascript type to act like a dictionary ? Pin
Izis29-Mar-17 10:54
Izis29-Mar-17 10:54 
QuestionIs this closure correct ? Pin
Izis29-Mar-17 7:27
Izis29-Mar-17 7:27 
I am trying to convert this code to use private variable inside a closure:

JavaScript
var cache = {};

function cachedAjax(url) {
	if (cache.hasOwnProperty(url)) {
		return cache[url];
	}
	var data = $.ajax({
		url: url,
		async: false
	}).responseText;
	cache[url] = data;
	return data;
}


so I wrote it like this:

JavaScript
var cachedAjax = (function (url) {
    var cache = {};
    
    if (cache.hasOwnProperty(url)) {
		  return cache[url];
	  }
	  var data = $.ajax({
		  url: url,
		  async: false
	  }).responseText;
	  cache[url] = data;
	  return data;
    
})();


Is this correct ?
AnswerRe: Is this closure correct ? Pin
Richard Deeming29-Mar-17 7:49
mveRichard Deeming29-Mar-17 7:49 
GeneralRe: Is this closure correct ? Pin
Izis29-Mar-17 8:56
Izis29-Mar-17 8:56 
QuestionPrint HTML file using ActiveX Pin
Christopher Cote27-Mar-17 3:36
Christopher Cote27-Mar-17 3:36 
SuggestionRe: Print HTML file using ActiveX Pin
Richard Deeming27-Mar-17 7:49
mveRichard Deeming27-Mar-17 7:49 
QuestionDynamicaly Created Controls using Javascripted is not posting while submitting theform Pin
Member 1308703727-Mar-17 2:12
Member 1308703727-Mar-17 2:12 
AnswerRe: Dynamicaly Created Controls using Javascripted is not posting while submitting theform Pin
F-ES Sitecore28-Mar-17 22:41
professionalF-ES Sitecore28-Mar-17 22:41 
QuestionElements hidden - if visible do something Pin
Member 1307408621-Mar-17 3:42
Member 1307408621-Mar-17 3:42 
QuestionRe: Elements hidden - if visible do something Pin
ZurdoDev21-Mar-17 4:19
professionalZurdoDev21-Mar-17 4:19 
AnswerRe: Elements hidden - if visible do something Pin
Member 1307408621-Mar-17 4:34
Member 1307408621-Mar-17 4:34 
GeneralRe: Elements hidden - if visible do something Pin
ZurdoDev27-Mar-17 1:59
professionalZurdoDev27-Mar-17 1:59 
Questiondataset with java Pin
Member 1307317120-Mar-17 22:01
Member 1307317120-Mar-17 22:01 
AnswerRe: dataset with java Pin
Richard MacCutchan20-Mar-17 23:06
mveRichard MacCutchan20-Mar-17 23:06 
QuestionDisplay PDF in iframe from base64 string using blob url Pin
ankit1819-Mar-17 6:03
ankit1819-Mar-17 6:03 
SuggestionRe: Display PDF in iframe from base64 string using blob url Pin
ZurdoDev20-Mar-17 1:15
professionalZurdoDev20-Mar-17 1:15 
QuestionA more efficient approach? Pin
samflex10-Mar-17 3:54
samflex10-Mar-17 3:54 
AnswerRe: A more efficient approach? Pin
Nathan Minier16-Mar-17 4:41
professionalNathan Minier16-Mar-17 4:41 
GeneralRe: A more efficient approach? Pin
samflex17-Mar-17 3:01
samflex17-Mar-17 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.