You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm loading the manifest from JSON, it's been encoded with $.my.tojson(manifest) and it works fine, but the var itemID variable that i declare before manifest is invisible to the itemID i have declared in the manifest code. Is the manifest code running in a different namespace?
var itemID = "something";
var manifest = manifestJson;
// Init $.my
$('.editForm').my(manifest, person);
Manifests passed as folded JSON never see local scope, only global. So they see window and all its members – but do not see local scopes.
Main consideration is safety. Since we have $.my.cache() that unfold manifest before caching, we must guarantee, that no code is executed while caching. So $.my does not use eval, it use new Function constructor, that is always executed in global scope (to be precise – without any scope).
To add local scope to manifest instance use this pattern:
put folded manifest to cache (it must have .id property)
when manifest needed, get it from cache – you‘ll receive unfolded clone – and augment/decorate it with functions, that can return all required data from local scope.
Or you can just mount your data directly to manifest before you start it.
This worked fine when the manifest was inline, but when loaded from JSON - any previously defined variables are unreachable.
The text was updated successfully, but these errors were encountered: