Expand Minimize

Do not declare code in the global namespace directly

Do not declare code in the global namespace directly. Instead consider using the $_global_ namespace pattern with Namespace registration, this will ensure correct execution with the MDS garbage collector

CheckId SPC058913
TypeName CodeDeclaredInGlobalNamespace
Severity Warning
Type JavaScriptFile

Bad Practice

var globalFooAddition = function(foo) {
  return foo + 1;
};

Good Practice
// Method accepts whole namespace chain, registers Namespaces and creates objects
Type.RegisterNamespace('MyApp');
MyApp.fooAddition = function(foo) {
  return foo + 1;
};

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.