Created
May 13, 2020 21:43
-
-
Save ramazankanbur/da0162dde1d23b78462d45bf50c7a68a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ES5 | |
// lib/math.js | |
LibMath = {}; | |
LibMath.sum = function (x, y) { | |
return x + y; | |
}; | |
LibMath.pi = 3.141593; | |
// someApp.js | |
var math = LibMath; | |
console.log('2π = ' + math.sum(math.pi, math.pi)); | |
// otherApp.js | |
var sum = LibMath.sum, | |
pi = LibMath.pi; | |
console.log('2π = ' + sum(pi, pi)); | |
//ES6 | |
// lib/math.js | |
export function sum(x, y) { | |
return x + y; | |
} | |
export var pi = 3.141593; | |
// someApp.js | |
import * as math from 'lib/math'; | |
console.log('2π = ' + math.sum(math.pi, math.pi)); | |
// otherApp.js | |
// Sadece ihtiyaç duyulan kod parçaları da dahil edilebilirdi. | |
import { sum, pi } from 'lib/math'; | |
console.log('2π = ' + sum(pi, pi)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment