Last active
September 2, 2016 19:03
-
-
Save reneviering/8d6eacf0d5906d196e578c60c99a5419 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 66: object-literal - getter | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('An object literal can also contain getters', () => { | |
it('just prefix the property with `get` (and make it a function)', function() { | |
const obj = { | |
get x() { return 'ax'; } | |
}; | |
assert.equal(obj.x, 'ax'); | |
}); | |
it('must have NO parameters', function() { | |
const obj = { | |
get x() { return 'ax'; } | |
}; | |
assert.equal(obj.x, 'ax'); | |
}); | |
it('can be a computed property (an expression enclosed in `[]`)', function() { | |
const keyName = 'x'; | |
const obj = { | |
get [keyName]() { return 'ax'; } | |
}; | |
assert.equal(obj.x, 'ax'); | |
}); | |
it('can be removed using delete', function() { | |
const obj = { | |
get x() { return 'ax'; } | |
}; | |
delete obj.x; | |
assert.equal(obj.x, void 0); | |
}); | |
// The following dont seem to work in the current transpiler version | |
// but should be correct, as stated here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get | |
// It might be corrected later, new knowledge welcome. | |
//it('must not overlap with a pure property', function() { | |
// const obj = { | |
// x: 1, | |
// get x() { return 'ax'; } | |
// }; | |
// | |
// assert.equal(obj.x, 'ax'); | |
//}); | |
// | |
//it('multiple `get` for the same property are not allowed', function() { | |
// const obj = { | |
// x: 1, | |
// get x() { return 'ax'; }, | |
// get x() { return 'ax1'; } | |
// }; | |
// | |
// assert.equal(obj.x, 'ax'); | |
//}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment