could you give me the hello world program for require.js

Manikandan Thiagarajan
Manikandan Thiagarajan used Ask the Experts™
on
could you give me the hello world program for require.js

i want to understand he require.js
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kent DyerIT Security Analyst Senior

Commented:
Ref.. http://www.w3schools.com/jsref/met_doc_write.asp

document.write("Hello World")

HTH,

Kent
Manikandan ThiagarajanSenior consultant

Author

Commented:
require js concept hello world program
In your page you include the require script, and specify a main script file to load:

<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <script data-main="main" src="scripts/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

Open in new window

In your main.js file you load other scripts, for example a display.js file:

require(["display"], function(util) {
   sayHello('world');
});

Open in new window

The display.js file containing a function used in the main.js file:

function sayHello(name) {
  alert('Hello ' + name);
}

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Manikandan ThiagarajanSenior consultant

Author

Commented:
cold you please give me the main.js file
Manikandan ThiagarajanSenior consultant

Author

Commented:
i am the new to the require.js

give me the full helloworld program to understand the require.js

and also specify the advantage
Manikandan ThiagarajanSenior consultant

Author

Commented:
can u zip it and send the file
Top Expert 2010

Commented:
Hey stmani, nothing other than this could help you :)

http://requirejs.org/docs/jquery.html
The program is already complete.

Save this as index.html:
<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <script data-main="main" src="scripts/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

Open in new window

Save this as main.js:
require(["display"], function(util) {
   sayHello('world');
});

Open in new window

Save this as display.js:
function sayHello(name) {
  alert('Hello ' + name);
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial