Skip to content

Instantly share code, notes, and snippets.

@ramazankanbur
Created May 13, 2020 21:43
Show Gist options
  • Save ramazankanbur/da0162dde1d23b78462d45bf50c7a68a to your computer and use it in GitHub Desktop.
Save ramazankanbur/da0162dde1d23b78462d45bf50c7a68a to your computer and use it in GitHub Desktop.
//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