w6d1 Flashcards

1
Q

Where is the best place to place reader.close() in an async loop?

A

At the end of the completion callback.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the boilerplate code for inheritance in JavaScript?

A
Function.prototype.inherits = function (BaseClass) {
  function Surrogate () {};
  Surrogate.prototype = BaseClass.prototype;
  this.prototype = new Surrogate();
};
function Dog (name) {
  this.name = name;
}

Dog.prototype.bark = function () {
console.log(this.name + “ barks!”);
};

function Corgi (name) {
  Dog.call(this, name);
}

Corgi.inherits(Dog);

Corgi.prototype.waddle = function () {
console.log(this.name + “ waddles!”);
};

var blixa = new Corgi(“Blixa”);

blixa. bark();
blixa. waddle();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a Function object contain?

A

A string which contains the JS code of the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you find the distance in a 2D vector?

A

Dist([x_1, y_1], [x_2, y_2]) = sqrt((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the norm of a vector, and how do you find it?

A

The vector’s magnitude/length; the speed of a velocity vector.

Norm([x_1, y_1]) = Dist([0, 0], [x_1, y_1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between a position vector and a velocity vector?

A

A position vector has an x and y position, while a velocity vector has a speed in the x and the y directions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly