js 類似php 靜態類的使用方法

2021-07-09 18:25:01 字數 739 閱讀 6327

可以定義乙個物件。

var fec = ,

eventtype: ,

isover: function(y, x, top, left, height, width) ,

isoveraxis: function(x, reference, size) ,

可以直接使用:

fec.keycode.enter

fec.isoveraxis: function(x, reference, size);

這樣有點像php的靜態類的使用,實際上是直接定義的物件

另外一種就是使用物件構造器。不過使用的時候需要new,構造器有點類似php中的類

function person(firstname,lastname,age,eyecolor)

{this.firstname=firstname;

this.lastname=lastname;

this.age=age;

this.eyecolor=eyecolor;

var myfather=new person("bill","gates",56,"blue");

var mymother=new person("steve","jobs",48,"green");

不適用構造器類似php的靜態類,直接使用

使用構造器,有點類似類,使用前需要new 出來物件。

php類常量定製及使用方法

例項 如下 to change this template,choose tools templates and open the template in the editor.description of classconstsample author liujl class classconst...

php類常量定製及使用方法

例項 如下 to change this template,choose tools templates and open the template in the editor.description of classconstsample author liujl class classconst...

js的with語句使用方法

1 簡要說明 with 語句可以方便地用來引用某個特定物件中已有的屬性,但是不能用來給物件新增屬性。要給物件建立新的屬性,必須明確地引用該物件。2 語法格式 with object instance 有時候,我在乙個程式 中,多次需要使用某物件的屬性或方法,照以前的寫法,都是通過 物件.屬性或者物件...