w5d6-7 Flashcards
In the styles pane in the elements tab in dev tools, what does a striked-through property represent?
A property that has been overridden by one above it (attributes are listed in descending order of precedence).
What does the ‘computed’ style tab represent?
It shows what CSS selector is providing a property value by clicking the dropdown arrow on the left.
How can you edit CSS directly in your browser, and allow your changes to persist?
You save over the file in your file system, then just remember to save it.
What must we do to round the result of any integer operation in JS?
Math.floor()
What is the boilerplate for command line I/O in JS?
var readline = require(‘readline’);
var reader = readline.createInterface({ // it's okay if this part is magic; it just says that we want to // 1. output the prompt to the standard output (console) // 2. read input from the standard input (again, console)
input: process.stdin,
output: process.stdout
});
T/F: A JS function will run even if it is passed too many or too few arguments.
T; if too few (or none) then the undefined parameters will have a value of ‘undefined’. If too many, then the excess arguments are stored in an array called ‘arguments’, along with the anticipated args.
How can we use Array methods on the arguments array?
Slice it:
// `arr.slice() == arr.slice(0, arr.length)` makes a copy of `arr`. var args = Array.prototype.slice.call(arguments); args.forEach(function (i) { console.log(i) });
Where is the slice method stored?
In Array.prototype because it is an “instance” method.
What does slice() do?
With no arguments, slice() returns a COPY of the array.
What does __proto__ point to?
The object’s prototype
What is the value of Object.prototype.__proto__
null; ‘Object’ is the “top level class”.
How can we create prototypal inheritance?
function Animal () {};
function Dog () {};
// Replace the default `Dog.prototype` completely! // `Dog.prototype.\_\_proto\_\_ == Animal.prototype`. Dog.prototype = new Animal();
function Poodle() {}; // Likewise with `Poodle.prototype`. Poodle.prototype = new Dog();
var myAnimal = new Animal(); var myDog = new Dog(); var myPoodle = new Poodle();
In the below example, why do we not just do Dog.prototype = Animal.prototype:
function Animal (name) { this.name = name; };
Animal.prototype.sayHello = function () {
console.log(“Hello, my name is “ + this.name);
};
function Dog () {};
// The surrogate will be used to construct `Dog.prototype`. function Surrogate () {}; // A `Surrogate` instance should delegate to `Animal.prototype`. Surrogate.prototype = Animal.prototype;
// Set `Dog.prototype` to a `Surrogate` instance. // `Surrogate.\_\_proto\_\_` is `Animal.prototype`, but `new // Surrogate` does not invoke the `Animal` constructor function. Dog.prototype = new Surrogate();
Dog.prototype.bark = function () {
console.log(“Bark!”);
};
Because this would mean that any function added to Dog would be added to Animal.
What does the following code accomplish:
function Dog (name, coatColor) { // call super-constructor function on **the current `Dog` instance**. Animal.call(this, name);
// `Dog`-specific initialization this.coatColor = coatColor; }
It allows us to call the initialization logic from Animal on the new Dog object.
What does Object.create do?
It returns a new object with its __proto__ set to its first argument:
Dog.prototype = Object.create(Animal.prototype);