Solved

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

Posted on 2012-12-21
8
416 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
Question by:stmani2005
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 8

Author Comment

by:stmani2005
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
 
LVL 8

Author Comment

by:stmani2005
ID: 38717939
cold you please give me the main.js file
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Author Comment

by:stmani2005
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 8

Author Comment

by:stmani2005
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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now