[英]Using server-side javascript in classic asp: what's wrong with “this”?
尝试开始在经典ASP中使用javascript。 不过,这似乎有些“陷阱”:任何有一定经验的人都可以告诉我“ Blah2”代码的最新情况吗? 似乎“应该”起作用,但是我对“ this”的使用似乎存在问题。
<script language="javascript" runat="server">
var Blah = {};
Blah.w = function(s){Response.write(s);}
Blah.w('hello'); //this works...
var Blah2 = function(){
this.w = function(s){Response.write(s);}
//line above gives 'Object doesn't support this property or method'
return this;
}();
Blah2.w('hello');
</script>
谢谢你的指导
提姆
您需要在功能周围添加括号
var Blah2 = (function(){
this.w = function(s){Response.write(s);}
//line above gives 'Object doesn't support this property or method'
return this;
}());
另外, this.w
并未执行您想要的操作。 this
实际上是指向那里的全局对象。 你要:
var Blah2 = (function(){
return {w : function(s){ Response.write(s); }};
}());
要么
bar Blah2 = new (function(){
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.