Javascript新手求教
Javascript中的构造函数和其他的函数本质上的区别是什么呢?我随便new一个函数会有什么结果呢?
[解决办法]
没区别,一个函数new一下会出现一个对象
[解决办法]
All functions in Javascript can be new, but then it is not meaning a function, it is a class so that I list an example to you:
function SuperTab()
{
this.testName = "aa";
alert(this == window);
alert(window.testName);
}
if you directly call the SuperTab, will alert true and "aa", because the scope is window for now.
if you new the SuperTab, will alert false and "undefined", because the scope is SuperTab, the variable "testName" is avaiable in the SuperTab.
[解决办法]
I specially suggest you some articles for learning the Javascript: Javascript Articles
[解决办法]
详细的你可以去看看javascript权威指南里面关于原型的章节,讲的非常详细。
你就把构造函数当成一般面向对象语言里面的构造函数好了, 用 new调用函数,来产生类的实例
[解决办法]