Created
December 19, 2012 00:09
-
-
Save anonymous/4333310 to your computer and use it in GitHub Desktop.
This file contains 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
(function(root) { // Wrap our entire code in anyonmous function. Minimise your chance to leak scope into the global namespace. See last line. | |
'use strict'; // http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it | |
var $ = root.$; // Convient access to the jQuery object. Chaining is expensive in JS. | |
root.Search = (function() { // Wrap the entire class in an anonymous function. This guarantees we will not leak scope. We assign the class to the root object. In this case, window. | |
function Search(el) { // Create a search object. This is also the constructor for the class. | |
this.el = el;// Assign an ivar | |
} | |
Search.prototype.perform = function() { // Instance method | |
// $ do something | |
} | |
return Search // Return the search object | |
})(); | |
$(root.document).on('keyup', '#search', function() { | |
new root.Search(this).perform(); | |
}); | |
}).call(this); // `this` in a global context is always the root object. In the browser, it's window. | |
test('perform works as intended', function() { | |
var search = new Search(); | |
ok(search); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment