在此代码中:
function myType(string){
this.string = string;
this.getName = function(){
//return this.name;
}
}
var myVar = new myType("string");
如果我使用myVar.getName()
,则应返回myVar
。我需要它来创建一个弹出框来改变页面的整个<body>
,所以对我来说这很重要。
我该怎么办?
编辑:
我要做的是编写一个自定义对象。这是步骤:
this.document_content
中
(2)hide():使用this.document_content
将正文更改为document.body.innerHTML
。<a>
按钮关闭弹出框。我发现问题出在2(1)
,我无法将变量名称放在onclick
的代码中。
我该怎么办?
答案 0 :(得分:0)
如果你想改变你的构造函数,你可以这样做 -
function myType(name, string){
this.string = string;
this.name = name;
this.getName = function(){
return this.name;
}
}
var myVar = new myType("myVar","string");
或者你可以创建一个哈希:
function myType(name, string){
this.string = string;
this.name = name;
this.getName = function(){
return this.name;
}
var res = {}
res[name] = this;
return res;
}
// Add response to an hash
var hash = {}
$.extend(hash, new myType("myVar","string"));