调用类向后变量 (JavaScript)
Call class backward variable (JavaScript)
我有这个休耕代码:
the_class = {
second_class : {
third_class : {
first_variable_name : "third class first variable",
fourth_class : {
first_variable_name : "forth class first variable",
first_function_name : function()
{
var out = "";
out += the_class.second_class.third_class.first_variable_name + "'n";
out += this.first_variable_name + "'n";
return out;
}
}
}
}
}
result = the_class.second_class.third_class.fourth_class.first_function_name();
alert(result);
结果:
third class first variable
forth class first variable
我需要在较低类位置的调用类变量。所以我使用:the_class.second_class.three_class.first_variable_name,但这是长!:(
有什么选项可以像这样调用反向类位置吗?我尝试了back.first_variable_name,backward.first_variable_name,没有人工作......:(
与文档中相同:../../../folder_name/file_name.txt
您可以添加对每个对象的父对象的引用。这将允许您执行所需的操作:
Myfourthclass = function(parentobj) {
this.parent = parentobj;
this.first_variable_name = "forth class first variable";
var _this = this;
this.first_function_name = function(){
return _this.parent.first_variable_name + "'n" +
_this.first_variable_name + "'n";
}
}
Mythirdclass = function(parentobj) {
this.parent = parentobj;
this.first_variable_name = "third class first variable";
this.fourth_class = new Myfourthclass(this);
}
Mysecondclass = function(parentobj) {
this.parent = parentobj;
this.third_class = new Mythirdclass(this);
}
Myfirstclass = function(){
this.second_class = new Mysecondclass(this);
}
newclass = new Myfirstclass();
alert(newclass.second_class.third_class.fourth_class.first_function_name());
相关文章:
- 将函数的上下文应用于javascript变量
- 如何通过ajax刷新JSF填充的javascript变量
- Javascript变量赋值|
- 限制javascript变量的最小/最大整数
- 来自文本输入null的html javascript变量
- 访问jsrender模板中的全局javascript变量并更新它
- 从数据库中获取数据并插入JavaScript变量
- 如何将javascript变量传递到Meteor Spacebars模板中
- 将JavaScript变量保存到Rails模型
- 在if语句下的html中使用javascript变量
- Javascript变量分配-按类别
- 操作javascript变量[HTML]以只显示文本
- 无法比较javascript变量
- 如何将smarty变量与javascript变量进行比较
- 如何使用PHP将javascript变量添加到mysql数据库中
- Javascript 变量使用 jquery 查找变量
- 重新加载页面时Javascript变量发生变化
- 在asp classic中使用javascript变量
- 全局Javascript变量变为null
- 如何向服务器端提交javascript变量