featuring Underscore, jQuery, Knockout, Backbone, Angular, Bootstrap, Clementine, and more!
A framework for creating ambitious web applications
App = Ember.Application.create();
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName')
});
App.IndexRoute = Ember.Route.extend({
model: function() {
var people = [
App.Person.create({
firstName: "Tom",
lastName: "Dale"
}),
App.Person.create({
firstName: "Yehuda",
lastName: "Katz"
})
];
return people;
}
});
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" id="index">
<h1>People</h1>
<ul>
{{#each model}}
<li>Hello, <b>{{fullName}}</b>!</li>
{{/each}}
</ul>
</script>
"Super-heroic JavaScript MVW Framework" - It's goal is to augment browser-based applications with model–view–controller (MVC) capability, in an effort to make both development and testing easier.
var todoApp = angular.module('todoApp', []);
todoApp.controller('TodoController', function($scope, $http) {
$scope.todos = [];
// Get all todos
$http.get('/todos')
.success(function(todos) {
$scope.loaded = true;
$scope.todos = todos;
}).error(function(err) {
alert(err);
});
$scope.addTodo = function(title) {
$http.post('/todos', {
title: title
}).success(function(todo) {
$scope.newTodoTitle = '';
$scope.todos.push(todo);
}).error(function(err) {
// Alert if there's an error
return alert(err.message || "an error occurred");
});
};
$scope.changeCompleted = function(todo) {
// Update the todo
$http.put('/todos/' + todo.id, {
completed: todo.completed
}).error(function(err) {
return alert(err.message || (err.errors && err.errors.completed) || "an error occurred");
});
};
$scope.removeCompletedItems = function() {
$http.get('/todos', {
params: {
completed: true
}
}).success(function(todos) {
todos.forEach(function(t) { deleteTodo(t); });
});
};
function deleteTodo(todo) {
$http.delete('/todos/' + todo.id, {
params: {
completed: true
}
}).success(function() {
// Find the index of an object with a matching id
var index = $scope.todos.indexOf(
$scope.todos.filter(function(t) {
return t.id === todo.id;
})[0]);
if (index !== -1) {
$scope.todos.splice(index, 1);
}
}).error(function(err) {
alert(err.message || "an error occurred");
});
}
});
<html ng-app="todoApp">
<head><!--import CSS, AngularJS, and Controller--></head>
<body>
<div ng-controller="TodoController" ng-cloak>
<h1>Tasks</h1>
<p id="empty" ng-hide="todos.length || !loaded">You don't have any todos! Add one now:</p>
<ul id="todos">
<li ng-repeat="todo in todos">
<label class="checkbox">
<input type="checkbox" ng-model="todo.completed" ng-change="changeCompleted(todo)" />
{{todo.title}}
</label>
</li>
</ul>
<form class="form-inline">
<input id="todo-title" type="text" ng-model="newTodoTitle" />
<button id="add-btn" class="btn btn-success" ng-click="addTodo(newTodoTitle)">Add</button>
</form>
<p>
<a href id="remove-completed-btn" ng-click="removeCompletedItems()">Remove completed items</a>
</p>
</div>
</body>
</html>
A lightweight set of tools for building pattern agnostic single-page web applications.
A "utility-belt library for JavaScript" that provides a lot of the functional programming support and LINQ-like syntax for dealing with arrays.
// _.each
var nums = [1,2,3,4,5,6];
_.each(nums, function(num, i) { print num; }); // 1,2,3,4,5,6
// _.find
_.find(people, function(person) {
return person.firstName == "Brett";
}); //Returns the first matching item in the array
// _.filter
var evenNums = _.filter(nums, function(num) {
return num % 2 == 0;
});
// _.where -- Slightly different than _.filter
_.where(people, {firstName: "John", age: 20});
[{firstName: "John", lastName: "Arndt", age: 20},
{firstName: "John", lastName: "Brown", age: 20}]
// _.template
//This pre-compiles the template.
var tmpl = _.template("Hi <%=title%>, welcome to <%=appName%>");
_.each(people, function(person) {
$('#greetings').append(tmpl({title: person.firstName, appName: app.name});
});
TDD/BDD unit testing frameworks for front-end JavaScript.
describe('#indexOf()', function(){
it('should return -1 when not present', function(){
[1,2,3].indexOf(4).should.equal(-1);
});
});
suite('Array', function(){
setup(function(){
// ...
});
suite('#indexOf()', function(){
test('should return -1 when not present', function(){
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});
A headless command-line WebKit browser for running automated unit tests.
Sleek, intuitive, and powerful front-end framework for faster and easier web development.
A Python-like programming language that transcompiles down to JavaScript.
A JavaScript automated task runner written in NodeJS.
A command line package manager for NodeJS applications and libraries.
Node's goal is to provide an easy way to build scalable network programs.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');