关于 yui3 JS 的问题
我有 2 个不同的 JS 文件:A.js 和 B.js。 A.js 看起来像这样:
YUI.use('a few modules',function(Y) {
var Spinner=function(config) {
//invoke a constructor
}
Spinner.NAME='spinnerobject';
Spinner.ATTRS={
status:{
value:false
,readonly:true
,broadcast:2
}
};
Y.extend(Spinner,Y.Base, {
initializer:
//many initializers here
, this.setstatus: function() {
//sets the status variable appropriately
}
});
});
B.js 是这样的:
YUI.use('a few modules',function(Y) {
var button_yui2 = Y.YUI2.widget.Button( { initializing parameters for button}
);
button_yui2.on('change',function(e){
spinnerobject.setstatus(); // call made to a function in A.js
});
我无法从 B.js 调用函数 setstatus。该函数根本没有执行。虽然没有抛出错误。这可能有什么问题?
I have 2 different JS files: A.js and B.js. A.js looks something like this:
YUI.use('a few modules',function(Y) {
var Spinner=function(config) {
//invoke a constructor
}
Spinner.NAME='spinnerobject';
Spinner.ATTRS={
status:{
value:false
,readonly:true
,broadcast:2
}
};
Y.extend(Spinner,Y.Base, {
initializer:
//many initializers here
, this.setstatus: function() {
//sets the status variable appropriately
}
});
});
B.js is this:
YUI.use('a few modules',function(Y) {
var button_yui2 = Y.YUI2.widget.Button( { initializing parameters for button}
);
button_yui2.on('change',function(e){
spinnerobject.setstatus(); // call made to a function in A.js
});
I'm not able to call the function setstatus from B.js. The function is not executed at all. Although no error is thrown. What might be the issue with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多事情与您发布的代码没有意义。你在哪里实例化 Spinner 对象?我会根据我认为您正在尝试做的事情来尝试提供帮助。
首先,您永远不会向系统注册微调器组件。在 a.js 中,您在 YUI.use 函数中声明 var spinner 。这使得无法从 yui.use 外部访问。您需要使用 yui.add 而不是 yui.use 或放置 Y.namespace('myNS').Spinner = Spinner;作为 a.js 的最后一行。这将使您的微调器组件作为 Y.myNS.Spinner 全局可用。
接下来,初始化器需要是一个函数:
并且 setstatus 应该只是传递给扩展的原型属性对象的成员
所以现在在 b.js 中,您可以初始化一个新的微调对象
希望这会有所帮助。抱歉,如果我没有理解你想要做什么。
there are a bunch of things that dont make sense with the code you posted. where are you instantiating a spinnerobject? i'll attempt to help based on what i think you're trying to do.
first off, you are never registering the spinner component with the system. in a.js, you declare var spinner inside the YUI.use function. That makes it impossible to access from outside that yui.use. you either need to use a yui.add instead of yui.use or put Y.namespace('myNS').Spinner = Spinner; as the last line of a.js. That will make your spinner component globally available as Y.myNS.Spinner.
next, initializer needs to be a function:
and setstatus should just be a member of the prototype properties object passed to extend
So now in b.js, you can initialize a new spinner object
hopefully this helps. sorry if i didnt grok what you were trying to do.