Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-12-21
8
Medium Priority
?
465 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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…
Suggested Courses

886 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