Javascript中的构造函数和其他的函数本质上的区别是什么呢?我随便new一个函数会有什么结果呢?

解决方案 »

  1.   

    没区别,一个函数new一下会出现一个对象
      

  2.   

    那这个对象里面的属性会怎么样呢?是不是如果函数中没有使用this关键字,这个被new出来的对象中就不会有任何属性?这么理解对吗?
    如果是这样,那函数中的那些代码与这个new出来的对象是什么关系呢?
    希望高手能深入分析一下。
      

  3.   

    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.
      

  4.   

    I specially suggest you some articles for learning the Javascript: Javascript Articles
      

  5.   

    详细的你可以去看看javascript权威指南里面关于原型的章节,讲的非常详细。
    你就把构造函数当成一般面向对象语言里面的构造函数好了, 用 new调用函数,来产生类的实例
      

  6.   


    I nerver seen the english guide for Javascript, it was written by me, I am interesting the Javascript so much, please let me know if you have any questions about Javascript. My personal website is: http://www.scriptlover.com
      

  7.   

    先产生一个 Object构造函数的对象,也就是  var o = new Object 或  var o = {}这样的
    然后在 这个最初的对象上面调用构造函数, 类似与  构造函数.call(o) 这样
    且新对象能共享构造函数的原型对象中的属性
      

  8.   

    http://topic.csdn.net/u/20090217/13/653f7949-9e0c-4e99-adb3-dcbc99fca8d5.html?6940今天早上看到的,感觉对你能有帮助
      

  9.   

    Well,thanks all the same,I'm learning Javascript these days,I have benefited so much from your website,thank you!
    Are you studying English now?I'm curious about the way you reply my questions,you know,I mean why you use English instead of Chinese.