【发布时间】:2021-09-13 11:09:29
【问题描述】:
当我在 chrome 中打开控制台时,会显示该对象。但是为什么我不能访问它呢?
错误: 未捕获的 ReferenceError:未定义画布 在:1:1
main.js
import { Canvas } from "./models/canvas.class.js";
const cvs = document.getElementById('cvs');
const ctx = cvs.getContext('2d');
let canvas = new Canvas(ctx);
function loop() {
canvas.getLog();
requestAnimationFrame(loop);
}
loop();
canvas.class.js
export class Canvas {
ctx;
constructor(ctx) {
this.ctx = ctx;
}
getLog() {
console.log(this);
}
}
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './src/js/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true
},
mode: 'development',
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: './src/index.html'
})
],
}
【问题讨论】:
标签: javascript google-chrome debugging webpack