[英]Javascript “this” pointer in Method Invocation Pattern not pointing to object
[英]Javascript The Method Invocation Pattern Sample is not working, why?
这是我在[Javascript-优秀部分]书中找到的摘录
它根本没有用。 IE8在“ var myObject ...”行中缺少“}”,描述为错误。
我错过了什么吗?
// Create myObject. It has a value and an increment
// method. The increment method takes an optional
// parameter. If the argument is not a number, then 1
// is used as the default.
var myObject = {
value: 0;
increment: function (inc) {
this.value += typeof inc === 'number' ? inc : 1;
}
};
myObject.increment( );
document.writeln(myObject.value); // 1
myObject.increment(2);
document.writeln(myObject.value); // 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.