Created
January 9, 2013 09:40
-
-
Save ynonp/4491926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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