Make load variable private
-
03-10-2020 - |
Question
I have the following function which retrieves the current user's properties:
function helper_redirect(){
this.clientContext = new SP.ClientContext.get_current();
this.oWeb = clientContext.get_web();
var peopleManager = new SP.UserProfiles.PeopleManager(this.clientContext);
personProperties = peopleManager.getMyProperties();
this.clientContext.load(personProperties);
this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded),
Function.createDelegate(this,this.onQueryFailed));
}
When I type in the console personProperties.get_userProfileProperties()['SID'];
it returns the current user's SID.
How can I make this variable not accessible in the console?
Solution
Declare your variable inside your function.
Right now you are missing the the var
part in front of its first appearance in your snippet, which means one of two things:
You have declared it elsewhere in your code and needs to protect it there
This is the first mention of it and you are not using the
var
for declaration of it, which leads to it being interpreted as a global variable by the JavaScript engine
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange