Start off by defining your enum...
MessageType.js
sap.ui.define([], function() {
"use strict";
return {
Unread: "Unread",
Read: "Read"
};
});
Next, mark this enum as a dependency in your custom control so that you are able to validate the value.
MyControl.js
sap.ui.define(["sap/ui/core/Control", "/path/to/MessageType.js"], function(Control, MessageType) {
Control.extend("myControl", {
someMethod: function(sMessageType) {
// Validate if we are dealing with a valid message type
var aKeys = Object.keys(MessageType);
var bValidEnumValue = aKeys.some(function(sKey) {
if (MessageType[sKey]) {
return true;
}
});
// Do other stuff..
}
});
});
Of course the way to check if you are dealing with a valid enum value can be implemented in different ways depending on what you're trying to do.
if (sMessageType === MessageType.Read) {
// do something
} else if (sMessageType === MessageType.Unread) {
// do something else
} else {
// throw an error?
}