问题描述
我有 2 个文件(FPDevice.js
和 FPComponent.js
)。每个文件都有一个对象。我需要从一个文件(Object)调用一个函数到另一个文件(Object)。
在文件 FPComponent.prototype.onSysexEvent.call(FPComponent);
文件上使用 FPDevice.js
可以正常工作,但没有达到预期效果。我期望通过在上下文参数中使用 FPComponent
而不是 this
,该函数将继承 FPComponent
对象的属性并能够使用 this.channels。>
-
当从
FPComponent.prototype.onSysexEvent.call(FPComponent);
函数调用FPMidiDevice.prototype.onSysexEvent
函数时,调用有效但继承无效。 -
出现错误 -
this.channels is undefined
-
由于
this.channels
是FPComponent
对象的属性,所以我需要调用FPComponent.prototype.onSysexEvent.call(FPComponent)
的继承来自FPComponent
对象,以便我可以使用this.channels
中的FPComponent.prototype.onSysexEvent
属性。
- 我正在寻找的结果是,一旦从
FPComponent.prototype.onSysexEvent
函数调用,函数FPComponent
就会从FPMidiDevice.prototype.onSysexEvent
对象继承属性。
FPDevice.js
//FPDevice.js
var __extends = (this && this.__extends) || (function ()
{
var extendStatics = function (d,b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d,b) { d.__proto__ = b; }) ||
function (d,b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b,p)) d[p] = b[p]; };
return extendStatics(d,b);
};
return function (d,b) {
extendStatics(d,b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype,new __());
};
})();
include_file("resource://com.presonus.musicdevices/sdk/controlsurfacecomponent.js");
include_file("resource://com.presonus.musicdevices/sdk/controlsurfacedevice.js");
include_file("FPComponent.js");
var FPMidiDevice = (function (_super)
{
__extends(FPMidiDevice,_super);
function FPMidiDevice(faderCount,sysexHeader)
{
var _this = _super.call(this) || this;
_this.faderCount = faderCount;
_this.sysexHeader = sysexHeader;
_this.lastActiveSensing = 0;
_this.activeSensingInterval = 2500;
return _this;
}
FPMidiDevice.prototype.onInit = function (hostDevice)
{
_super.prototype.onInit.call(this,hostDevice);
this.meters = [];
};
FPMidiDevice.prototype.onSysexEvent = function (data,length)
{
//########################################################################################################## //##########################################################################################################
// I am trying to use call but using FPComponent object so the call can inherit the properties from FPComponent
FPComponent.prototype.onSysexEvent.call(FPComponent);
};
return FPMidiDevice;
}(PreSonus.ControlSurfaceDevice));
function createFP16DeviceInstance()
{
return new FPMidiDevice(16,FP.Support.kSysexHeaderFP16);
}
FPComponent.js
//FPComponent.js
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d,new __());
};
})();
include_file("resource://com.presonus.musicdevices/sdk/controlsurfacecomponent.js");
include_file("resource://com.presonus.musicdevices/sdk/controlsurfacedevice.js");
var FPComponent = (function (_super)
{
__extends(FPComponent,_super);
function FPComponent(faderCount)
{
var _this = _super.call(this) || this;
_this.faderCount = faderCount;
_this.pagingStatusIndex = faderCount - 1;
_this.channels = [];
return _this;
}
FPComponent.prototype.onInit = function (hostComponent)
{
PreSonus.ControlSurfaceComponent.prototype.onInit.call(this,hostComponent);
this.model = hostComponent.model;
this.root = this.model.root;
this.mixerMapping = this.root.find("mixerMapping");
this.channelBankElement = this.mixerMapping.find("ChannelBankElement");
var paramList = hostComponent.paramList;
for (var i = 0; i < this.faderCount; i++)
{
var channel = new ChannelStrip;
channel.channelElement = this.channelBankElement.getElement(i);
channel.textValue = paramList.addalias("textValue" + i);
channel.panValue = paramList.addalias("panValue" + i);
channel.muteValue = paramList.addalias("muteValue" + i);
channel.solovalue = paramList.addalias("solovalue" + i);
channel.recordValue = paramList.addalias("recordValue" + i);
channel.monitorValue = paramList.addalias("monitorValue" + i);
channel.colorValue = paramList.addalias("colorValue" + i);
this.channels.push(channel);
}
};
//########################################################################################################
// it is not working properly when called from FPMidiDevice.prototype.onSysexEvent on file FPMidiDevice.js
// error = this.channels is undefined
FPComponent.prototype.onSysexEvent = function ()
{
var channelIndex = 0;
var channel = this.channels[channelIndex];
channel.faderValue.value = 1;
};
return FPComponent;
}(PreSonus.ControlSurfaceComponent));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)