To begin with, I'm a noob to JavaScript. How do I add functionality to the main loop, or something similar?

Recommended Answers

All 3 Replies

Hi,

you mean how to add conditional statements to a loop? For example:

var test = 'oranges';

['apples', 'oranges', 'mango'].forEach(function (elem, index) {

    // conditional statement
    if (elem == 'oranges') {
        console.log('Chosen element: ' + elem);
    }

    // default condition
    else {
        console.log('Something else.');
    }
});

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

I'm trying to find a way to add functionality to Java Script's main event loop, from which the all its events are evaluated.

For example,

//every event based application has something similar at heart,
//usually, somewhere in the main function
while(application.isRunning()) 
{
 //process all events
 AbstractEvent **a = eventStack.begin()-1;
 while(++a!=eventStack.end())
 {
  application.processEvent(*a); //could be an "onclick","onmouseenter", exit, etc...
  //for Java Script, can I make stuff happen here
 }

 //or here?
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.