This repository was archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path6-objects.js
More file actions
121 lines (101 loc) · 3.89 KB
/
6-objects.js
File metadata and controls
121 lines (101 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
@description
Javascript object are structure represented that may have data, properties or functions,
an object has a dynamic type, which can be any dynamic or primitive type.
For utilize the object declare:
@argument var
@argument let
@argument const
@argument class
@argument Object
@var {Object} exampleObject, as declared utilizing @argument var,
are utilize {} to representation of object, into object their properties
can be declare between "", '' or none, by default utilize "", after declare, set the value with :,
this value declared use "", '', `` to string or none to numbers.
to most property separete with ,
this have two properties:
@argument {number} data
@argument {string} properties
@example
**/
var exampleObject = {
"data": 1,
"properties": "Hello object",
};
console.log(exampleObject); // {data: 1, properties: "Hello object"}
/**
An object can own another object, as in the example.
@var {Object} objectIntoAnother
@example
**/
var objectIntoAnother = {
"objectInto": {
"innerData": 2
},
"data": 1
}
console.log(objectIntoAnother) // {objectInto: {…}, data: 1}
/**
To access property of object, insert . after its representation or ["name property"].
@example
**/
console.log(objectIntoAnother.data) // 1
console.log(objectIntoAnother["data"]) // 1
/**
An object can declare a function into property value.
@example
**/
var objectFuction = {
"myFunction" : function() {
console.log("Hello function");
}
}
objectFuction.myFunction();
/**
@description
The object in javascript can instance another objects, following the object-oriented programming model.
Exist two types of instances.
@class ClassExample
added in ECMAScript 2015, is most utilized to instance objects.
In to example is utilized the method constructor, which receives by parameters two properties.
@param {String} textParam
@param {number} numberParam
@argument {Object} this utilize to reference of class.
@example
**/
class ClassExample {
constructor(textParam, numberParam) {
this.textParam = textParam;
this.numberParam = numberParam;
}
}
/**
Utilize the @argument new, what create an object instance @class Person
@example
**/
var classExample = new ClassExample("Hello class", 1);
console.log(classExample.textParam); // "Hello class"
console.log(classExample.numberParam); // 1
/**
There are also object instance per function declaration.
In to example is utilized the method constructor, which receives by parameters two properties.
@argument {Object} InstanceFunction
@param {String} textParam
@param {number} numberParam
@argument {Object} this Also here utilize to reference of function/object.
@example
**/
var InstanceFunction = function(textParam, numberParam) {
this.textParam = textParam;
this.numberParam = numberParam;
}
/**
Utilize the @argument new, what create an object instance @argument {Object} InstanceFunction
@example
**/
var instanceFunction = new InstanceFunction("Hello instance function", 2);
console.log(instanceFunction.textParam); // "Hello instance function"
console.log(instanceFunction.numberParam); // 2
/**
function methods and property of class and object, will be treated in a separate file.
**/