JavaScript可以扩展一个对象以使用另一个类'成员方法?
我当前问题的一些背景:我一直在使用Adobe Animate生成HTML5画布并创建我的前端画布元素:标签,文本字段和MovieClip对象。这些充当我的多功能对象。原因是,如果我使用传统按钮,任何弹出对话框都会在我的按钮后面绘制。我已经尝试了多种解决这个问题的方法,但最终我用MovieClip对象替换了按钮对象,这解决了我遇到的分层问题。
现在进入我当前的问题:我仍然需要一些MovieClip对象作为按钮。我在项目文件中创建了一个类,并将其称为BasicButton。它具有一些核心功能,我的MovieClip对象将需要任何对象像按钮一样起作用。
class BasicButton {
constructor(obj){
this.obj = obj;
}
}
function onMouseHover() {
console.log('Hovering over' + this.obj);
}
function onMouseDown() {
console.log('MouseDown on' + this.obj);
}
在我的主.html
文件中,我设法访问了我的MovieClip项目,该项目命名为FakeButton_1,并且是类型movieclip
。
<html>
..head
..body
<script .. create.js />
<script src="./BasicButton.js" />
<script>
funtion onLoad(){
extractRoot('canvas').FakeButton_1.text = "Hello World"; //testing I can change the text of this object and it works!
//TODO: now make FakeButton_1 extend or make it of type BasicButton
}
</script>
</html>
我的问题是,我可以说FakeButton_1是否扩展了基本键?理想情况下,我将不得不将其fakebutton_1对象传递到basic button构造函数中,然后知道它正在操纵哪个对象。
我还开始研究此文章确认fakebutton_1。
任何帮助将不胜感激。
A bit of background for my current issue: I've been using Adobe Animate to generate HTML5 canvas and create my front-end canvas elements: labels, text fields, and MovieClip objects as well. These are acting as my multipurpose objects. Reason being is that if I use traditional buttons any pop up dialog gets drawn behind my buttons. I've tried a number of ways to get around this issue but in the end I ended up replacing my buttons objects with MovieClip objects and that solved the layering issue I was having.
Now onto my current issue: I still need some of my MovieClip objects to act as buttons. I created a class in my project file and called it BasicButton. Its got some core functionalities that my MovieClip objects will need in order for any object to act like a button.
class BasicButton {
constructor(obj){
this.obj = obj;
}
}
function onMouseHover() {
console.log('Hovering over' + this.obj);
}
function onMouseDown() {
console.log('MouseDown on' + this.obj);
}
In my main .html
file I managed to get access to my MovieClip item which is named FakeButton_1 and is of type MovieClip
.
<html>
..head
..body
<script .. create.js />
<script src="./BasicButton.js" />
<script>
funtion onLoad(){
extractRoot('canvas').FakeButton_1.text = "Hello World"; //testing I can change the text of this object and it works!
//TODO: now make FakeButton_1 extend or make it of type BasicButton
}
</script>
</html>
My question is how, then, can I say FakeButton_1 extends BasicButton? Ideally I would have to pass it FakeButton_1 object into BasicButton constructor so then it knows which object it is manipulating.
I also started looking into this article but I cant seem to find a way to get BasicButton to acknowledge FakeButton_1.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论