Google News
logo
CoffeeScript - Interview Questions
Explain Modules in CoffeeScript
ES2015 modules are supported in CoffeeScript, with very similar import and export syntax :
import './local-file.js' # Must be the filename of the generated file
import 'package'
​
import _ from 'underscore'
import * as underscore from 'underscore'
​
import { now } from 'underscore'
import { now as currentTimestamp } from 'underscore'
import { first, last } from 'underscore'
import utilityBelt, { each } from 'underscore'
​
import dates from './calendar.json' assert { type: 'json' }
​
export default Math
export square = (x) -> x * x
export class Mathematics
  least: (x, y) -> if x < y then x else y
​
export { sqrt }
export { sqrt as squareRoot }
export { Mathematics as default, sqrt as squareRoot }
​
export * from 'underscore'
export { max, min } from 'underscore'
export { version } from './package.json' assert { type: 'json' }
import './local-file.js';
​
import 'package';
​
import _ from 'underscore';
​
import * as underscore from 'underscore';
​
import {
  now
} from 'underscore';
​
import {
  now as currentTimestamp
} from 'underscore';
​
import {
  first,
  last
} from 'underscore';
​
import utilityBelt, {
  each
} from 'underscore';
​
import dates from './calendar.json' assert {
  type: 'json'
};
​
export default Math;
​
export var square = function(x) {
  return x * x;
};
​
export var Mathematics = class Mathematics {
  least(x, y) {
    if (x < y) {
      return x;
    } else {
      return y;
    }
  }
​
};
​
export {
  sqrt
};
​
export {
  sqrt as squareRoot
};
​
export {
  Mathematics as default,
  sqrt as squareRoot
};
​
export * from 'underscore';
​
export {
  max,
  min
} from 'underscore';
​
export {
  version
} from './package.json' assert {
    type: 'json'
  };
 
Advertisement