Created
June 30, 2015 22:42
-
-
Save KieronWiltshire/57a6884a144b211c4258 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
// | |
// My 'exceptions.js' file | |
// | |
var createError = require('create-error'); | |
/** | |
* InvalidSubjectType exception | |
* | |
* This exception should be thrown if the subject type | |
* provided to the object constructor doesn't exist. | |
*/ | |
exports.InvalidSubjectType = function(type) { | |
return createError('InvalidSubjectType', { | |
messages: [ | |
"The subject type provided doesn't exist:", | |
type | |
] | |
}); | |
}; | |
// | |
// My 'subject.js' file | |
// | |
var exceptions = require('./exceptions.js'); | |
/** | |
* A Permission Subject. | |
* | |
* @param id | |
* @param type | |
* @constructor | |
*/ | |
function Subject (id, type) { | |
if (typeof type !== "string") throw exceptions.InvalidSubjectType(type); | |
this.id = id; | |
this.type = type; | |
/** | |
* Get the subject identifier. | |
* | |
* @returns {*} | |
*/ | |
this.getId = function() { | |
return this.id; | |
} | |
/** | |
* Get the subject type. | |
* | |
* @returns {string|*} | |
*/ | |
this.getType = function() { | |
return this.type; | |
} | |
} | |
new Subject(1, 1); | |
// The issue that I'm getting: | |
// http://puu.sh/iIMhr/b644ff3493.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment