Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-12-21
8
Medium Priority
?
461 Views
Last Modified: 2012-12-26
could you give me the hello world program for require.js

i want to understand he require.js
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 38715112
Ref.. http://www.w3schools.com/jsref/met_doc_write.asp

document.write("Hello World")

HTH,

Kent
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38715135
require js concept hello world program
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 38715368
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

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38717939
cold you please give me the main.js file
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38717940
i am the new to the require.js

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

and also specify the advantage
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38717944
can u zip it and send the file
0
 
LVL 15

Expert Comment

by:StealthyDev
ID: 38719902
Hey stmani, nothing other than this could help you :)

http://requirejs.org/docs/jquery.html
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 2000 total points
ID: 38720067
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

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question