I am analyzing some angular js source code of angular-file-upload
plugin and I have some problems trying to understand some code.
I know that export
is part of the new ES6 standards and it used to export functions and objects from a given file (or module).
But the following syntax is a bit weird me :
let {
copy,
extend,
forEach,
isObject,
isNumber,
isDefined,
isArray,
element
} = angular;
export default (fileUploaderOptions, $rootScope, $http, $window,
FileLikeObject, FileItem) => {
let {
File,
FormData
} = $window;
class FileUploader {
// class implemention....
}
return FileUploader;
}
What is the use of the =>
operator in this statement?
Export default is used when there is only one export to be made from a particular file and when importing this one element, we don't have to worry about giving the same name to our import. This combination of export and import allows us to implement modularity.
To export arrow functions in JavaScript, we can use export directly with arrow functions. const hello = () => console. log("hello"); export default hello; to export the hello function as a default export with export default .
Export default means you want to export only one value the is present by default in your script so that others script can import that for use. This is very much necessary for code Reusability.
If a module's primary purpose is to house one specific export, then you should consider exporting it as a default export. This makes both importing and actually using the import a little easier. Further, TypeScript recommends named exports when there are multiple things to export [4].
This is an arrow function (or fat arrow function):
(a, b, c) => { /* ... */ }
Is (almost) equivalent to:
function(a, b, c) { /* ... */ }
The only difference between arrow functions and functions declared with function
is that this
has lexical binding in arrow functions instead of the confused morass of binding in regular functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With