javascript 关闭,不工作?
我有一个函数,我调用它来检索滑动窗格(telerik splitter 控件) 我想我可以使用这个功能,
function getZone() {
var slidingZone = $find("<%= slidingZone.ClientID %>");
return function () { return slidingZone; };
}
这样它就不必每次都“找到”滑动区域。但这不起作用。
这确实...
function getZone() {
var slidingZone = $find("<%= slidingZone.ClientID %>");
return slidingZone;
}
你能告诉我为什么第一个不起作用吗?
顺便说一句,我就是这样使用的......
function hideTreePane() {
var paneId = "<%= slidingPane.ClientID %>";
getZone().undockPane(paneId);
return true;
}
I have a function that I call to retrieve a sliding pane (telerik splitter control)
I thought I could use this function
function getZone() {
var slidingZone = $find("<%= slidingZone.ClientID %>");
return function () { return slidingZone; };
}
so that it didn't have to "find" the sliding zone every time. But it doesn't work.
This does...
function getZone() {
var slidingZone = $find("<%= slidingZone.ClientID %>");
return slidingZone;
}
Can you tell me why the first one isn't working?
BTW, I'm using it like this....
function hideTreePane() {
var paneId = "<%= slidingPane.ClientID %>";
getZone().undockPane(paneId);
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
因为你返回一个函数并且你需要评估它......
如果使用第一个功能,这可能会起作用。
Because your returning a function and you need to evaluate it...
If using the first function this may work..
您需要调用从 getZone 返回的函数:
它不起作用,因为函数
getZone
本身没有名为undockPane
的成员。编辑:
我认为这样做会更好:
然后你会这样调用:
You will need to call the function you are returning from getZone:
It wasn't working because the function
getZone
itself does not have a member calledundockPane
.EDIT:
I think it would be better to do this:
Then you would call like this:
好吧,第一个函数返回一个函数,并且您希望执行内部函数。
如果您调用它的结果,您将看到它工作,例如:
我认为您想要以下内容,使用立即执行的匿名函数,仅调用
$find
方法一次,存储其结果:Well, the first function, returns a function, and you want the inner function to be executed.
If you invoke the result of it you will see it work, e.g.:
I think you want the following, use an immediately executed anonymous function, to call the
$find
method only once, storing its result:在第一个示例中,您返回一个函数,因此
getZone()
本身成为一个函数,您需要执行getZone()()
来获取slidingZone
你想要的值。在这种情况下,无需将返回值包装在函数中。
In your first example you're returning a function, therefore
getZone()
becomes a function itself and you need to dogetZone()()
to get theslidingZone
value you want.There's no need to wrap your return value in a function for this case.
您从第一个示例返回一个函数,而不是一个值。您需要评估该功能才能使其正常工作。尝试类似的东西。
最好将其作为“类”的一部分,以便缓存变量不在全局范围内。
You're returning a function from the first example, not a value. You'd need to evaluate the function for it to work. Try something like.
It would be better for this to be part of a "class" so that the caching variable isn't in the global scope.