小编Vee*_*hoo的帖子

在PHP中,为什么我能够以静态方式访问非静态方法?

在以下代码中,nonStatic()不是静态方法.即使这样,我也能够在不创建对象的情况下(以静态方式)访问它.任何人都可以帮助我理解,因为这在Java等其他语言中是不可能的吗?

<?php
class MyClass
{
    function nonStatic() {
        echo "This can be printed";
    }
}
MyClass::nonStatic(); // This can be printed
Run Code Online (Sandbox Code Playgroud)

php static

8
推荐指数
2
解决办法
686
查看次数

Array(n)和[... Array(n)]之间的区别

为什么下面的代码中map()输出有区别?

var y = [1,2,2,1];

var t = y.map(ind => [...Array(ind)].map((_,i) => ind+""+i));
// This makes [ [ '10' ], [ '20', '21' ], [ '20', '21' ], [ '10' ] ]

var t1 = y.map(ind => Array(ind).map((_,i) => ind+""+i));
//[ [ <1 empty item> ], [ <2 empty items> ], [ <2 empty items> ], [ <1 empty item> ] ]
Run Code Online (Sandbox Code Playgroud)

javascript arrays spread-syntax map-function

8
推荐指数
1
解决办法
94
查看次数

标签 统计

arrays ×1

javascript ×1

map-function ×1

php ×1

spread-syntax ×1

static ×1