function Person (name, age) {
    this.name = name;
    this.age = age;
}

好像建構子,可以new Person();

var ageDifference = function(person1, person2) {
    return person1.age - person2.age;
}

這卻是方法,是像static 方法

function Circle (radius) {
    this.radius = radius;
    this.area = function () {
        return Math.PI * this.radius * this.radius;
        
    };
    // define a perimeter method here
    
};

像是建構子內,可以放方法

var a1=new Array();

建立陣列方法和JAVA不同 ,JAVA要給定空間!

 

字串相比可以使用"====",JAVA則需要Equl

function add(firstName, lastName,  email, phoneNumber) {
contacts[contacts.length] = {
    firstName: firstName,
    lastName: lastName,
    phoneNumber: phoneNumber,
    email: email
};
}

可以無限增加陣列內的值!!!

var nyc = {
    fullName: "New York City",
    mayor: "Bill de Blasio",
    population: 8000000,
    boroughs: 5
};
這是物件nyc

arrow
arrow
    全站熱搜

    程式小試身手 發表在 痞客邦 留言(0) 人氣()