作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此代码在子级中使用继承 我在场景中添加了一些在父级中声明的东西 我该怎么做 它在子级中看到场景时出错
function parent (domElement, renderStatistics) {
this.scene = new THREE.Scene();
}
function child(domElement) {
parent.call(this, domElement);
this.init();
}
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = Young;
child.prototype.init = function () {
function createLab(geometry) {
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial());
this.scene.add(mesh); // this error Cannot call method 'add' of undefined
}
}
最佳答案
child.prototype.init = function () {
var _this = this;
function createLab(geometry) {
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial());
_this.scene.add(mesh);
}
}
关于javascript - 我如何在子 javascript 代码中使用父变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13810458/
我是一名优秀的程序员,十分优秀!