« Back to Index

Curl Example

View original Gist on GitHub

Tags: #js

Person.js

define(function() {
	
	return function Person(fullname) {
		this.name = fullname;
	}
	
});

index.html

<!doctype html>
<html dir="ltr" lang="en">
<head>
	<meta charset="utf-8">
	<title>Curl (Cujo Resource Loader)</title>
</head>
<body>
	<script type="text/javascript">
		curl = {
		    baseUrl: 'Assets/Scripts',
		    paths: {
		        curl: 'Curl',
		        jquery: 'Utils/jquery'
		    }
		};
	</script>
	<script src="Assets/Scripts/Curl.js"></script>
	<script type="text/javascript">
		curl(['App/people'], function(o) {
			console.log(o.list, o.scripts);
		});
	</script>
</body>
</html>

people.js

define(['Models/Person', 'Utils/random', 'jquery'], function (Person, randomUtility, $) {
	
	var people = [],
	    scriptsOnPage = $('script');
	
	people.push(new Person('Jim'));
	people.push(new Person(randomUtility.someValue));
  
	return { list: people, scripts: scriptsOnPage };
	
});

random.js

define(function() {
	
	function method (x) {
		return x + x;
	}
 
	return {
		someValue: 'foobar',
		myMethod: method
	}
	
});