Click here to Skip to main content
15,918,041 members
Home / Discussions / JavaScript
   

JavaScript

 
Rant[Repost] how to calculate the number of working hours in Week excluding Weekends in JavaScript or jquery using Moment.js Pin
Richard Deeming12-Oct-17 3:53
mveRichard Deeming12-Oct-17 3:53 
QuestionExecute functions based on certain time delay and ignore other functions execution Pin
Member 1346008011-Oct-17 16:11
Member 1346008011-Oct-17 16:11 
AnswerRe: Execute functions based on certain time delay and ignore other functions execution Pin
Karthik_Mahalingam16-Oct-17 1:31
professionalKarthik_Mahalingam16-Oct-17 1:31 
QuestionJSON with number as key Pin
V.11-Oct-17 2:42
professionalV.11-Oct-17 2:42 
AnswerRe: JSON with number as key Pin
Afzaal Ahmad Zeeshan11-Oct-17 6:37
professionalAfzaal Ahmad Zeeshan11-Oct-17 6:37 
GeneralRe: JSON with number as key Pin
V.11-Oct-17 20:05
professionalV.11-Oct-17 20:05 
QuestionHow to hide f12 devloper tool from the browser? Pin
Member 1345865211-Oct-17 0:30
Member 1345865211-Oct-17 0:30 
AnswerRe: How to hide f12 devloper tool from the browser? Pin
F-ES Sitecore11-Oct-17 1:03
professionalF-ES Sitecore11-Oct-17 1:03 
QuestionAngular releases Pin
BrunoFaitalaas9-Oct-17 22:36
BrunoFaitalaas9-Oct-17 22:36 
AnswerRe: Angular releases Pin
Nathan Minier10-Oct-17 2:44
professionalNathan Minier10-Oct-17 2:44 
GeneralRe: Angular releases Pin
Karthik_Mahalingam11-Oct-17 21:21
professionalKarthik_Mahalingam11-Oct-17 21:21 
PraiseRe: Angular releases Pin
Jeremy Falcon7-Nov-17 22:30
professionalJeremy Falcon7-Nov-17 22:30 
QuestionWhy not the output is 3 in java script object for the line console.log(home.count) Hope i am making it clear. Pin
Member 110968437-Oct-17 5:14
Member 110968437-Oct-17 5:14 
AnswerRe: Why not the output is 3 in java script object for the line console.log(home.count) Hope i am making it clear. Pin
Richard Deeming9-Oct-17 8:52
mveRichard Deeming9-Oct-17 8:52 
Because the return statement at the end of the home function creates a copy of the value of the count variable at the point where the method returns. There is no connection between that copy and the local variable, so when the "work" functions update the local variable, that change is not reflected in the returned object.

Imagine how difficult it would be to write code in a language where that was not the case!
JavaScript
var x = 42;
var y = x;
x = 0; // What value should y have at this point?

You'll need to change the returned object so that count is a function that returns the current value of the local variable:
JavaScript
var home = function() {
    ...
    return {
        caller: caller,
        count: function(){
            return count;
        }
    };
};

var h = home();
h.caller().job1();
h.caller().job2();
h.caller().job1();
console.log(h.count());




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionBug in try catch statement can I can't find where. Pin
Jason Lemon3-Oct-17 16:11
Jason Lemon3-Oct-17 16:11 
GeneralRe: Bug in try catch statement can I can't find where. Pin
PIEBALDconsult3-Oct-17 17:28
mvePIEBALDconsult3-Oct-17 17:28 
QuestionRe: Bug in try catch statement can I can't find where. Pin
Richard MacCutchan3-Oct-17 21:44
mveRichard MacCutchan3-Oct-17 21:44 
AnswerRe: Bug in try catch statement can I can't find where. Pin
Karthik_Mahalingam4-Oct-17 17:53
professionalKarthik_Mahalingam4-Oct-17 17:53 
AnswerRe: Bug in try catch statement can I can't find where. Pin
ZurdoDev11-Oct-17 9:48
professionalZurdoDev11-Oct-17 9:48 
AnswerRe: Bug in try catch statement can I can't find where. Pin
Weavr8-Apr-18 1:58
Weavr8-Apr-18 1:58 
QuestionJavascript Pin
Member 134419482-Oct-17 15:59
Member 134419482-Oct-17 15:59 
AnswerRe: Javascript Pin
Richard MacCutchan2-Oct-17 21:51
mveRichard MacCutchan2-Oct-17 21:51 
AnswerRe: Javascript Pin
GKP19923-Oct-17 23:52
professionalGKP19923-Oct-17 23:52 
AnswerRe: Javascript Pin
Karthik_Mahalingam4-Oct-17 17:51
professionalKarthik_Mahalingam4-Oct-17 17:51 
QuestionDocument.OnKeyDown Pin
Member 1342709424-Sep-17 10:58
Member 1342709424-Sep-17 10:58 

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.