What is object, property, function and method in Javascript? - Wen2012/Learning-note-for-C- GitHub Wiki
Object
- javascript's fundamental datatype.
- a collection of properties or named values
- a composite value: aggregates multiple values, (primitive or other objects)
- store and retrieve these values by their names
- an unordered collection of properties
- Object is to map strings to values.
- Any value in Javascript that is not a string, a number, true, false, null or undefined is an object.
object types
- objects, arrays, and functions
property
- a name: a string
- a value:
#method
- When the value of a property is a function, we call it a method.
Example
var s = "test"; s.len = 4; var t =s.len;
when you run the code, the value of t is undefined. The second line of code creates a temporary String object, set its len property to 4, and then discards that object. The third line creates a new string object from the original string value and then tries to read the len property. This property does not exist, and the expression evaluates to undefined.
This demonstrates that strings, numbers, and boolean values behave like objects when you try to read the value of a property (or method) from them.
temporary objects: wrapper object to wrapped primitive value.
Objects are sometimes called reference types to distinguish them from javascrip's primitive types. object values are references.