Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created January 9, 2013 09:40
Show Gist options
  • Save ynonp/4491926 to your computer and use it in GitHub Desktop.
Save ynonp/4491926 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>ABook</title>
</head>
<body>
<ul>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="abook.js"></script>
</body>
</html>
/**
* Created with JetBrains WebStorm.
* User: ynonperek
* Date: 1/9/13
* Time: 10:01 AM
* To change this template use File | Settings | File Templates.
*/
(function() {
"use strict";
/**
*
* @param $el - jQuery ul element
* @constructor
*/
var AddressBook = function( $el ) {
var self = this;
self.contacts = [ 'Jim', 'Jerry' ];
self.render = function() {
for ( var i=0; i < self.contacts.length; i++ ) {
$el.append('<li>' + self.contacts[i] + '</li>');
}
};
self.addNewContact = function( name ) {
self.contacts.push( name );
self.render();
};
};
var abook = new AddressBook($('ul'));
abook.render();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment