javascript - js里面首字母大写的“构造函数”和一个类中双下划线开头的“构造函数”的区别?

WBOY
Release: 2016-06-06 20:10:44
Original
1201 people have browsed it

在js中,首字母大写的这种函数,如下:

<code>function Person(){
//
};</code>
Copy after login
Copy after login

可叫做“构造函数”,
在一个类中,比如:(php为例)

<code>class Man extends Person
{
    public function __construct()
    {
        //
    }
 }</code>
Copy after login
Copy after login

__construct()也叫“构造函数”,
这两种都叫“构造函数”,有什么区别?

回复内容:

在js中,首字母大写的这种函数,如下:

<code>function Person(){
//
};</code>
Copy after login
Copy after login

可叫做“构造函数”,
在一个类中,比如:(php为例)

<code>class Man extends Person
{
    public function __construct()
    {
        //
    }
 }</code>
Copy after login
Copy after login

__construct()也叫“构造函数”,
这两种都叫“构造函数”,有什么区别?

语法而已,话说php也支持类名函数就是构造方法的,双下划线的是php5.3引入的,以前不支持

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!