0

This is a long shot, but is it possible to have a default method or property on a Javascript object, one that gets invoked when you reference a property that doesn't exist?

For example,

foo.js:

export default {
  hello: 'hello',
  world() {
    return 'world';
  },
  defaultProperty() {
    return 'defaultValue';
  }
}

bar.js:

import foo from 'foo.js';
console.log(foo.hello); // 'hello'
console.log(foo.unknownFunction()); // 'defaultValue'
console.log(foo.unknownProperty); // 'defaultValue'
ccleve
  • 15,239
  • 27
  • 91
  • 157

0 Answers0