在 JavaScript 中扩展属性
我在javascript中有这段代码:
var object = {
get: function(id){
sel = document.getElementById(id);
sel.orig = {};
...
return object.extend(sel, object);
}
extend: function(el, opt){
for(var name in opt) el[name] = opt[name];
return el;
}
}
在另一个js中我有
var Multi = {
set: function(){
if(!this.orig["height"]) this.orig["height"] = this.offsetHeight;
...
return this;
}
}
object.extend(object,Multi);
这样的代码:
object.get('myId').set();
但是在“set”方法中,属性this.orig[“height”]总是未定义的,所以它总是会改变值这不是这个想法,我需要第一次捕获它,因为我试图制作一个 Fx 框架,而我那是用于 SlideUp 功能的,我需要保持原始高度,这样我可以再次返回。
有什么想法吗?谢谢
i have this code in javascript:
var object = {
get: function(id){
sel = document.getElementById(id);
sel.orig = {};
...
return object.extend(sel, object);
}
extend: function(el, opt){
for(var name in opt) el[name] = opt[name];
return el;
}
}
and in another js i have
var Multi = {
set: function(){
if(!this.orig["height"]) this.orig["height"] = this.offsetHeight;
...
return this;
}
}
object.extend(object,Multi);
and i call it like this:
object.get('myId').set();
but when in the "set" method, the property this.orig["height"] is always undefined, so it always will change the value and that's not the idea, i need to capture it the first time because im trying to make an Fx framework and i that's for the slideUp function, i need to keep the original height, so i can go back again.
Any ideas please? thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在,与一些人的
answers评论完全没有建设性相反,我认为你真正的问题是关于这个小小曲:以及为什么它返回未定义?它不......你的问题出在别处,因为这是有效的:
Now, in contrast to some people's
answerscomments being completely non constructive I assume your true question regards this little ditty:and why it returns undefined? It does'nt... your problem lies elsewhere, because this works:
嘿,感谢您的评论和 Quickredfox 的整体回答!我发现了问题,在这一部分:
我刚刚更改为:
瞧!非常感谢您的回答!
hey, thanks for the comments and overall for the answer Quickredfox!! i found the problem, in this part:
i just changed to this:
and voila!! thank you very much for your answer!