JavaScript: Objects, Methods, Prototypes
JavaScript: Objects, Methods, Prototypes
Computer Science and Engineering College of Engineering The Ohio State University
Lecture 25
What is an Object?
Computer Science and Engineering The Ohio State University
Property: a key/value pair
aka name/value pair
Object: a partial map of properties
Keys must be unique
Creating an object, literal notation
let myCar = { make: "Acura", year: 1996, plate: "NKR462" };
To access/modify an object's properties:
myCar.make = "Ford"; // cf. Ruby
myCar["year"] = 2006;
let str = "ate";
myCar["pl" + str] == "NKR463"; //=> true
Object Properties
myCar
Computer Science and Engineering The Ohio State University
make "Ford" year 2006 plate "NKR463"
Arrays vs Associative Arrays
Computer Science and Engineering The Ohio State University
04 1 "hi" 2 3 3.14
0 true 1 true 2 false
age 4 greeting "hi"
doors pi 3.14
0 true 1 true 2 false
Dynamic Size, Just Like Arrays
Computer Science and Engineering The Ohio State University
Objects can grow
myCar.state = "OH"; // 4 properties let myBus = {}; myBus.driver = true; // adds a prop myBus.windows = [2, 2, 2, 2];
Objects can shrink
delete myCar.plate;
// myCar is now { make: "Ford",
//
year: 2006, state: "OH" }
Object Properties
myCar
Computer Science and Engineering The Ohio State University
make "Ford" year 2006 plate "NKR463"
Object Properties
Computer Science and Engineering The Ohio State University
myCar
myCar.state = "OH";
make "Ford" year 2006 plate "NKR463" state "OH"
Object Properties
Computer Science and Engineering The Ohio State University
myCar
delete myCar.plate;
make year state
"Ford" 2006 "OH"
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- csci 104 hash tables usc viterbi
- parsing json
- understanding json schema
- chapter 9 scraping sites that use javascript and ajax
- json quick guide tutorialspoint
- javascript mock test ii tutorialspoint
- for javascript developing fosdem
- javascript notes for professionals
- ilovecoding javascriptcheatsheet
- javascript objects methods prototypes
Related searches
- most mysterious objects ever discovered
- unexplained objects found on earth
- hidden objects free games no time limit
- 10 unexplained objects on earth
- 100 hidden objects free games
- free games hidden objects no time limits
- javascript array of objects example
- javascript array of objects find
- javascript methods list
- objects in javascript examples
- javascript sort array of objects by field
- javascript object methods and properties