Permalink
Browse files

Use an init function.

Otherwise using a Vimulator.Base as a prototype will bind the key events
to the prototype, not the instance.
  • Loading branch information...
georgebrock committed Nov 30, 2012
1 parent 3ea7b2f commit 48b0865f998ce2e4d751abd246674c538ae75aa3
Showing with 8 additions and 10 deletions.
  1. +1 −1 index.html
  2. +3 −3 js/base.js
  3. +1 −3 js/demo.js
  4. +1 −1 test.html
  5. +1 −1 tests/helpers.js
  6. +1 −1 tests/unit/base.js
View
@@ -30,7 +30,7 @@
<script src='js/words.js'></script>
<script src='js/demo.js'></script>
<script>
- window.vimulator = new Vimulator.Demo('#vimulator');
+ window.vimulator = new Vimulator.Demo().init('#vimulator');
</script>
</body>
</html>
View
@@ -1,9 +1,7 @@
(function () {
window.Vimulator = {};
- Vimulator.Base = function () {
- this.init.apply(this, arguments);
- };
+ Vimulator.Base = function () {};
Vimulator.Base.prototype.init = function (container) {
this.modes = {
@@ -21,6 +19,8 @@
this.lines = this.textContainer.text().split('\n');
this.render();
+
+ return this;
};
Vimulator.Base.prototype.setMode = function (name) {
View
@@ -1,7 +1,5 @@
(function () {
- Vimulator.Demo = function () {
- this.init.apply(this, arguments);
- };
+ Vimulator.Demo = function () {};
Vimulator.Demo.prototype = new Vimulator.Base();
Vimulator.Demo.prototype.delay = 500;
View
@@ -31,7 +31,7 @@
<script src='js/insert_mode.js'></script>
<script src='js/words.js'></script>
<script>
- window.vimulator = new Vimulator.Base('#vimulator');
+ window.vimulator = new Vimulator.Base().init('#vimulator');
</script>
<!-- Test helpers -->
View
@@ -12,7 +12,7 @@ function pressEscape() {
function reset(text) {
$('#vimulator pre').text(text);
- window.vimulator = new Vimulator.Base('#vimulator');
+ window.vimulator = new Vimulator.Base().init('#vimulator');
}
function currentText() {
View
@@ -2,7 +2,7 @@ describe("Base", function () {
var vim;
beforeEach(function () {
- vim = new Vimulator.Base();
+ vim = new Vimulator.Base().init();
});
describe(".mode", function () {

0 comments on commit 48b0865

Please sign in to comment.