2) JS Objects Flashcards

1
Q

What are four ways of creating an object?

A

1.) Object literal (literally give the prop name and value) 2.) Object Constructor (Instantiate new object, then use dot notation) 3.) Prototypal Pattern (Instantiate an empty function, then give property name and value using prototype keyword) 4.) Constructor Pattern (create function, with arguments, and use the this keyword to give property values to prop. names)

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

How would you access the properties of an object?

A

Dot notation and bracket notation, using the property name and value.

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

How do JS objects fit in the overall scheme of the PE behavior layer.

A

Objects are ultimately the most important thing in OOP languages because they are the core fundamental essence of how the code works. If everything is an object then it is vital the programmer knows how to manipulate and use the tools at his disposal. JS is behavior and allows coders to do at least three things, which is storing data, modifying html, and communicating with the server (typically using AJAX). All these things are performed using data that is stored in JS, or retrieved with JS and then modified, or created in JS (by way of functions and other objects), or data is pulled from servers. Programmers often say that when programming you’re mostly doing the same thing over and over again, and that thing you’re doing, to oversimplify, is creating todo lists and sending and receiving them. All we’re doing when we code is using data, allowing for data to be created and then at some point using that very data. Period. If you can understand the forms in which data can take by way of objects then you can master the more complex attributes of JS and be a great developer, it would seem to me.

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

What types of data types are there, give both the 5 different types as well as the two kinds there are.

A

AVCOJ (a vitamin c orange juice) : array, variables, cookies, objects, json. The two categories into which every JS data type can be put in is primitive and not-primitive (anything that is not living is primitive, and since objects are the only living JS objects they are the only things that can be considered not-primitive). Anything that is not primitive is considered a reference, weirdly enough.

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

Object data types have attributes, what are they (in plain english)?

A

The most obvious attributes an object has are its property name and property value, if you were to describe a car by its attributes you’d use its color:blue, topSpeed:100mph after all. However the object data type also has 3 other attributes that aren’t obvious: configurable attribute, enumerable, writable. All three attributes are set to true by default. What are they? Every object has configurable attributes (attributes can be deleted or changed), can have enumerable attributes, and has properties that can be changed.

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

How do you access an objects enumerable/countable attributes?

How do I dig inside an object?

A

To access an objects attributes you’d have to use a for loop. Typically in a for loop you’re stating a variable, stating a limit of that variable, and then giving the loop a concatenating command. To write a for loop that pulls out all the attributes in an object you MUST know that the in keyword IS EXTREMELY POWERFUL. All you’d have to do is use a variable, any variable and say

for(x in myObject){console.log(x)}

The for/in loop!

However note that an objects attributes that were inherited from object.prototype will not be accessible by the for/in loop.

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

Explain ‘own’ and ‘inherited’ property as it relates to objects.

A

Objects have their own properties, and objects can also inherit properties of other objects if those objects were initialized as copies of another object. So for example if we used the constructor method to create an object we’d say:

var newObject = new object( );

But we could also make a copy of another object

var redObject = new newObject( );

This way teh redObject will inherit all the properties of the first object.

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

Could you right now

(a) create an object.
(b) give it properties.
(c) delete its properties.
(d) create a new object that inherits all the first objects properties.
(e) Use a for loop to print out all the objects properties

A

Just do it

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

What must be done to send your object via HTTP request?

A

HTTP must be serialized and then must be deserialized to use. Serialization just means transfering an objects content into a string.

You’re using the JSON data type to save your objects, and then to stringify/serialize or deserialize you;re using Parse or stringify.

JSON.stringify( myObject );

JSON.parse( myObject );

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