Java Script 的面向对象编程

var myGrade = {};//创建一个Object


var collegeAlgebra = {
    level: "freshman",
    difficulty: "hard",
    expectedGrade: 98,

    textbook: function(){
        console.log("college Algebra for freshman is the required text");
    }

}

delete collegeAlgebra .level;//删除collegeAlgebra 的level属性

var collegeAlg = new Object; //创建一个Object


collegeAlg.level = "freshman";
collegeAlg.textbook = function(){
    console.log("college Alg for freshman is the required text");
} //collegeAlg["textbook"] = function(){console.log("college Alg for freshman is the required text");}


console.log(myGrade);
console.log(collegeAlgebra);
collegeAlgebra.textbook();
console.log(collegeAlg);
collegeAlg.textbook();

你可能感兴趣的:(Java Script 的面向对象编程)