A deep dive in the Vue.js source code (#31): the allowedGlobals function
This is the 31st post in a series examining the Vue.js source code line-by-line.
allowedGlobals function calls the
makeMap function and passes concatenated strings.
As we discussed in post six,
makeMap is a function that “make[s] a map and return[s] a function for checking whether a key is in that map.” The function:
- takes a string and a boolean as parameters,
- creates an empty object,
- splits the string at each comma,
- and loops through the split string setting each item as a key on the map to true.
- Finally, makeMap returns a function (creating a closure) for checking whether a key is in the map. If expectsLowerCase is true, it looks for the lowercase key by calling toLowerCase(). Otherwise, it just looks for the key passed as a parameter
Turning back to the
has method of the
hasHandler object from the last post:
It now makes more sense.
has will call the
warnNonPresent function if (a) the key is not on the target or its prototype or (b) if the key is not one of the whitelisted allowed globals or does not start with an underscore.
If you are just joining us, this is the 32nd post in a series examining the entire Vue.js source code. Follow me on…medium.com
SERIES TABLE OF CONTENTS