CSE 130 Lecture Notes - Lecture 2: Eval

37 views3 pages
12 Jan 2018
What is a callback? A name for a function that is passed to another function
-we expect it to be”called” back
Modules - JS did NOT originally have modules!
const secret = “cse130 is fun!”;
exports.myVar = 42;
exports.myFunc = function(x) {
If (x === secret) {
} else {
console.log(‘guess again!’);
//IMPLICITLY returns undefined
What does require() do?
Function requireMyModule() {
const exports = {};
myModule(exports); //populates this object!
return exports;
What are JavaScript Objects?
-maps of names or symbols (strings) to values
-can NOT be a function to a value
-object literal notation:
const obj = { x: 3, y: “w00t” }
-obj.x or obj[“x”] ← 2nd one requires lookup in a table (slowoer)
-methods are “funcion-valued properties”
-obj.f = function(y) { return this.x + y; }
What is “this”?
-the receiver
- comes from Self (Smalltalk dialect)
- thing that “receives” the message you are trying to convey
points to the object which has the function as a method
const obj = {
“x-w00t”: 10, //obj.x-w00t = obj.x - w00t ← does NOT WORK!
//have to use obj[“x-w00t”]
console.log(obj.f.call({ x:45 }, 4)) //50
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.