What is the difference between JavaScript and object-oriented in PHP?

Source: Internet
Author: User
Tags learn php
Front-end development novice. The main learning JS. Because a long time ago business needs to learn PHP, also written for some time PHP, but still use a process-oriented way of writing, also know that PHP does not directly support polymorphism and so on. There are not too many things to compare the object-oriented programming ideas of two languages. Want to know more about the two weak types of scripting language in the object-oriented thinking what is the difference? And the pros and cons of both languages in object-oriented programming? Sincerely ask questions, want to learn, I really do not want the following technical aspects of the answer, but by "PHP is the best language" brush screen.

Reply content:

Who told you that PHP does not support polymorphism?


The difference between modern JavaScript (es2015+) and modern PHP (PHP7) is actually narrowing (the mainstream language is used to learn from each other, so the longer the more like). In OO facilities, PHP has interface and trait, with Public/protected/private. In addition PHP has typehint. These JS are not yet at the moment. However, if you value these, you can use typescript, in addition to no trait, other aspects of the explosion of PHP. JS is based on objects. So JS is really not the object-oriented in the strict sense. Although recently es2015 out a grammar sugar class, but actually what is going on. , press F12, and enter "new Class a{}":
ignore the recruitment and this cross-domain error ..... Ignore the recruitment and this cross-domain error .....
Prototype prototype is the same as the JS feature, the name of the constructor function is the declaration of the class,,,
Think it's object-oriented to declare with class ... Nature is still something that many years ago.

For PHP this whole world * * * * *.
As far as the PHP7 of the new century is concerned, his grammar is more generalized, is a more conventional object-oriented, and c++\java\c# and the like are relatively close, nothing too special place.

Both in thought, I feel that JS is a strange trick (historical baggage Heavy), PHP is more traditional (but dare to discard the bad things before).

Learning JS Object-oriented is difficult (inheritance alone has a bunch of methods) ~ ~ This disadvantage is obvious.
But PHP is easier to learn than it is. Common language archetype inherits JavaScript is unique
class inherits a subset of the prototype inheritance in a sense PHP is the same as the language of all the face objects, but it does not seem like Java-like polymorphism in PHP. But it still doesn't prevent it from being the language of the face object. JS's face object and all the face object language (such as php,java,c#) are not the same, JS is not a typical high-level language of the face object of the language, it is a functional language, his face object is in the form of a function, for a specific object JS can be directly in the form of literal declaration, The object of the high-level language of the face object must be new.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.