'Use Strict' -- Feeling Trendy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2015 12:21 PM
So I was feeling trendy and started writing script includes using 'use strict' at the start of all my functions. 'use strict' apparently works great because it tells me things like "GlideRecord" and "gs" are not defined.
However, when I use the script include, everything works because ServiceNow is declaring GlideRecord somewhere outside my script include (like it always does). Is there a way to edit the script editor to tell it what function declarations to ignore?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 02:28 PM
In Istanbul, I get those errors if I use 'use strict' outside of function scopes:
'use strict';
var TaskTopTask = Class.create();
...
But if I use it within functions, I get no complaints. I usually use a pattern like this to hide and hoist. If you use the standard ServiceNow pattern, you might need to specify 'use strict' in each function scope.
var TaskTopTask = Class.create();
(function staticScope(ttt) {
'use strict';
ttt.prototype = (function prototypeScope(p) {
p.type = 'TaskTopTask';
p.initialize = function instanceScope(task) {
copyToTaskTop(); // Hoisted function
this.copyToTaskTop = copyToTaskTop; // non-private function
function copyToTaskTop() {
var task.isUsableHere();
};
}; // End instanceScope
return p;
})({}); // End prototypeScope
var ENUM = (ttt.ENUM = {
ONE: 1,
TWO: 2,
});
})(TaskTopTask); // End staticScope