nlmap中定义了一个
// (Any) => Boolean
isMap = function(x) {
return x._type === "nl_map";
};
导致null和undefined的字符串化只在声明了nlmap扩展的情况下报错
TypeError: Cannot read properties of undefined (reading '_type')
不完全懒加载:
指每次初始化后extensions/all中的扩展都会init一次但是不在nl中声明扩展就不导出prims和porter
function() {
// (C) Uri Wilensky. https://github.com/NetLogo/Tortoise
var extensionPaths;
extensionPaths = [
'array',
'bitmap',
'csv',
'encode',
'dialog',
'export-the',
'fetch',
'fp',
'http-req',
'import-a',
'logging',
'matrix',
'mini-csv',
'nlmap',
'nt',
'palette',
'send-to',
'sound',
'store',
'string',
'table',
// Followings are Turtle Universe extensions
'plot',
'tutorial',
'widget',
'workspace',
'nettango',
'sensor',
'tune',
'phys',
'xr'
];
module.exports = {
initialize: function(workspace, ...importedExtensions) {
var extensions, upperNames;
upperNames = importedExtensions.map(function(name) {
return name.toUpperCase();
});
extensions = {};
extensionPaths.forEach(function(path) {
var extension, extensionModule, upperName;
extensionModule = require(`extensions/${path}`);
extension = extensionModule.init(workspace);
upperName = extension.name.toUpperCase();
if (upperNames.includes(upperName)) {
return extensions[upperName] = extension;
}
});
return extensions;
},
porters: function(...importedExtensions) {
var porters, upperNames;
upperNames = importedExtensions.map(function(name) {
return name.toUpperCase();
});
porters = [];
extensionPaths.forEach(function(path) {
var extensionModule, upperName;
extensionModule = require(`extensions/${path}`);
if (extensionModule.porter != null) {
upperName = extensionModule.porter.extensionName.toUpperCase();
if (upperNames.includes(upperName)) {
return porters.push(extensionModule.porter);
}
}
});
return porters;
}
};
}