我在 JavaScript 类上使用静态异步方法时遇到问题。如果我删除 static 关键字,它可以很好地在类中调用,但我将无法使用该类来调用它。
User.exist(email)我期望的结果是在类本身上使用和在类的实例上使用存在方法,例如foo.exist(email)。
我觉得哪里不对呢?
const userEmails = []
class User {
constructor(fields) {
this.email = fields.email;
this.name = fields.name;
}
static async exist(email) {
return setTimeout(function() {
return userEmails.includes(email)
}, 2000)
}
async storeEmail() {
let userExist = await this.exist(this.email)
if (userExist) {
console.log('User exist')
} else {
users.push(this.email)
console.log(userEmails)
}
}
};
let foo = new User({email: 'foo@bar.com', name: 'Foo Bar'})
foo.storeEmail() // this.exist is not a function
User.exist('foo@bar.com') // Works when used …Run Code Online (Sandbox Code Playgroud) 我想使用 Three.js 显示用户上传的 STL 文件。
\n\n我的文件通过 GET 请求发送到前端:res.sendFile(path)。问题是,如果不编辑 Three.js 的加载器,我就无法使用该原始数据来加载文件!
有人可以帮我编辑STLLoader以接受结果res.sendFile(path)而不是路径(URL)吗?
经过一周的绞尽脑汁,我还是没有运气!
\n\n这是 STLLoader.js 的代码:
\n\nimport {\n BufferAttribute,\n BufferGeometry,\n DefaultLoadingManager,\n FileLoader,\n Float32BufferAttribute,\n LoaderUtils,\n Vector3\n} from "three/build/three.module.js";\n\n\nvar STLLoader = function ( manager ) {\n\n this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;\n\n};\n\nSTLLoader.prototype = {\n\n constructor: STLLoader,\n\n load: function ( url, onLoad, onProgress, onError ) {\n\n var scope = this;\n\n var loader = new FileLoader( scope.manager );\n loader.setPath( …Run Code Online (Sandbox Code Playgroud)