Skip to content

Commit

Permalink
refactoring to pseudoclassical complete
Browse files Browse the repository at this point in the history
  • Loading branch information
paloma-vel committed Nov 13, 2018
1 parent 1e7740c commit ecb156a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
15 changes: 8 additions & 7 deletions src/blinkyDancer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var makeBlinkyDancer = function(top, left, timeBetweenSteps) {
// this.blinkyDancer = new Dancer(top, left, timeBetweenSteps);

Dancer.call(this);

this.top = top;
this.left = left;
// Dancer.call(this);
makeDancer.call(this, top, left, timeBetweenSteps);
// this.top = top;
// this.left = left;
this.timeBetweenSteps = timeBetweenSteps;
var oldStep = this.step;

// we plan to overwrite the step function below, but we still want the superclass step behavior to work,
// so we must keep a copy of the old version of this function
Expand All @@ -18,11 +17,11 @@ var makeBlinkyDancer = function(top, left, timeBetweenSteps) {
// return blinkyDancer;
};

makeBlinkyDancer.prototype = Object.create(Dancer.prototype);
makeBlinkyDancer.prototype = Object.create(makeDancer.prototype);
makeBlinkyDancer.prototype.constructor = makeBlinkyDancer;


//makeBlinkyDancer.prototype.oldStep = blinkyDancer.prototype.step;
makeBlinkyDancer.prototype.oldStep = makeDancer.prototype.step;

makeBlinkyDancer.prototype.step = function() {
// call the old version of step at the beginning of any call to this new version of step
Expand All @@ -35,3 +34,5 @@ makeBlinkyDancer.prototype.step = function() {





18 changes: 9 additions & 9 deletions src/dancer.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// Creates and returns a new dancer object that can step
var Dancer = function(top, left, timeBetweenSteps) {
this.top = top;
this.left = left;
var makeDancer = function(top, left, timeBetweenSteps) {
// this.top = top;
// this.left = left;
this.timeBetweenSteps = timeBetweenSteps;

// use jQuery to create an HTML <span> tag
this.$node = $('<span class="dancer"></span>');

//console.log('What is this? How do we refer to this in a meaning context?', this);
this.step();
// I THINK that 'this' refers to the newly instantiated object
makeDancer.prototype.step.call(this);

this.setPosition(top, left);

};


Dancer.prototype.step = function() {
makeDancer.prototype.step = function() {
// the basic dancer doesn't do anything interesting at all on each step,
// it just schedules the next step

setTimeout(this.step.bind(this), this.timeBetweenSteps); //refactor setTimeout with bind
};

Dancer.prototype.setPosition = function(top, left) {
makeDancer.prototype.setPosition = function(top, left) {
// Use css top and left properties to position our <span> tag
// where it belongs on the page. See http://api.jquery.com/css/
//
var styleSettings = {
top: this.top,
left: this.left
top: top,
left: left
};
this.$node.css(styleSettings);
};
3 changes: 3 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ $(document).ready(function() {
});
});


// somewhere, we need a 'new' keyword!

0 comments on commit ecb156a

Please sign in to comment.