国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript がオブジェクトを作成する

JavaScript は、一般的に使用されるいくつかの組み込みオブジェクト (後述) を提供しますが、場(chǎng)合によっては、特別で豊富な機(jī)能を?qū)g現(xiàn)するためにオブジェクトをカスタム作成する必要があります。

たとえば、「student」オブジェクトを作成し、それにいくつかのプロパティとメソッドを割り當(dāng)てます:

student = new Object();  // 創(chuàng)建對(duì)象“student”
student.name = "Tom";   // 對(duì)象屬性 名字
student.age  = "19";    // 對(duì)象屬性 年齡
student.study =function() {   // 對(duì)象方法 學(xué)習(xí)
    alert("studying");
};
student.eat =function() {     // 對(duì)象方法 吃
    alert("eating");
};

さらに、次のようなオブジェクトを作成することもできます:

var student = {};
student.name = "Tom";
……

または次のようなオブジェクト:

var student = {
    name:"Tom";
     age:"19";
    ……
}

ただし、上記のメソッドは複數(shù)のオブジェクトを作成します。 の場(chǎng)合、繰り返しコードが大量に生成されるため、関數(shù)を使用して新しいオブジェクトを作成することもできます:

function student(name,age) {
    this.name = name;
    this.age = age;
    this.study = function() {
        alert("studying");
    };
    this.eat = function() {
        alert("eating");
    }
}

次に、new を通じて Student オブジェクトのインスタンスを作成します:

var student1 = new student('Tom','19');
var student2 = new student('Jack','20');
<!DOCTYPE html>
<html>
<body>
<script>
person={firstname:"Bill",lastname:"gates",age:56,eyecolor:"blue"}
document.write(person.firstname + " is " + person.age + " years old.");
</script>
</body>
</html>


學(xué)び続ける
||
<html> <head> <script type="text/javascript"> var person = { name: "dongjc", age: 32, Introduce: function () { alert("My name is " + this.name + ".I'm " + this.age); } }; person.Introduce(); </script> </head> <body> </body> </html>
提出するリセットコード