" in php similar (aka equivalent) to "." in javascript? In other words, php $object->method(); and $object->property = 'someValue'; ...">

"->" in php similar (aka equivalent) to "." in javascript?

In other words, php

$object->method();

and

$object->property = 'someValue';

equivalently js:

$object.method();

and

$object.property = 'someValue';

I'm curious, or is my understanding of php and js messed up?

+5
source share
4 answers

Similar, but still great.

One big but not exclusive! - the difference is that in PHP methods are tied to an instance of the class, whereas in JavaScript methods are just functions (which are first-class values), which are called properties ("stored") objects.

Since PHP methods are bound to an instance of the class, this means that $thisinternally it does not change depending on how the method is called.

JavaScript, , object.member(...) object["member"].call(object, ...): this JavaScript , . ( JavaScript this.)

/ (, , !), , . "" , , , - .

.

+9

.

, JavaScript , .

+4

: " " - "".

, , ( ), , . Javascript, . , !

+1

, PHP - , Javascript - . , , , ?

: "is" → " php, ". " javascript?"

Answer No. None. Since in PHP you must first create an object of the class and then use this object. If in JS (JavaScript) there is no need for a class.

Using both PHP and JS appropriately can help you make a good site ...

-1
source

All Articles