You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+130Lines changed: 130 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,6 +147,57 @@ greet(); // Hello World!
147
147
### Classes
148
148
The classes are introduced as syntactic sugar over existing prototype based inheritance and constructor functions. So this feature doesn't bring new object-oriented inheritance model to JavaScript.
149
149
150
+
### Modules
151
+
Modules are small units of independent, reusable code to be used as the building blocks in a Javascript application.
152
+
153
+
Prior to ES6, there was no native modules support in JavaScript. There were 3 major module standards used,
154
+
155
+
1. Asynchronous Module Definition (AMD)
156
+
2. RequireJS Modules
157
+
3. CommonJS Modules (module.exports and require syntax used in Node.js)
158
+
159
+
ES6 has provided the built-in support for modules. Everything inside a module is private by default, and runs in strict mode. Public variables, functions and classes are exposed using `export` statement.
160
+
161
+
**Export Statement:**
162
+
There are two types of exports:
163
+
164
+
1. Named Exports (Zero or more exports per module)
165
+
166
+
You can export each element or a single export statement to export all the elements at once
167
+
168
+
```js
169
+
constPI=Math.PI;
170
+
171
+
functionadd(...args) {
172
+
returnargs.reduce((num, tot) => tot + num);
173
+
}
174
+
175
+
functionmultiply(...args) {
176
+
returnargs.reduce((num, tot) => tot * num);
177
+
}
178
+
179
+
// private function
180
+
functionprint(msg) {
181
+
console.log(msg);
182
+
}
183
+
184
+
export { PI, add, multiply };
185
+
```
186
+
187
+
2. Default Exports (One per module)
188
+
189
+
If we want to export a single value, you could use a default export
190
+
191
+
```js
192
+
// module "my-module.js"
193
+
194
+
exportdefaultfunctionadd(...args) {
195
+
returnargs.reduce((num, tot) => tot + num);
196
+
}
197
+
```
198
+
199
+
**Import Statement:**
200
+
150
201
### Set
151
202
Set is a built-in object to store collections of unique values of any type.
152
203
```js
@@ -467,6 +518,85 @@ let john = Reflect.construct(
467
518
console.log(john instanceof User);
468
519
console.log(john.fullName); // John Doe
469
520
```
521
+
522
+
2. **Calling a function using Reflect.apply():**
523
+
Prior to ES6, you can invoke a function with a specified `this` value and arguments by using the `Function.prototype.apply()` method.
524
+
525
+
For example, you can call `max()` static method of Math object,
3. **Defining a property using Reflect.defineProperty():**
538
+
The `Reflect.defineProperty()` method is similar to `Object.defineProperty()` but it returns a Boolean value indicating whether or not the property was defined successfully instead of throwing an exception.
console.log('Cannot define the age property on the user object.');
568
+
569
+
}
570
+
```
571
+
572
+
4. **Delete property using Reflect.deleteProperty():**
573
+
574
+
The `Reflect.deleteProperty()` method is used to delete properties like the delete operator but as a function. It returns Boolean value indicating whether or not the property was successfully deleted.
5. **Get property of an object using Reflect.get():**
587
+
The `Reflect.get` method is used to get a property on an object like the property accessor syntax but as a function.
588
+
589
+
```js
590
+
constuser= {
591
+
name:'John',
592
+
age:33
593
+
};
594
+
595
+
console.log(Reflect.get(user, 'age')); // 33
596
+
```
597
+
598
+
6. **:**
599
+
470
600
### Proper Tail Calls
471
601
**Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.
0 commit comments