SoFunction
Updated on 2025-04-13

JavaScript writing method seven


//Define the class name
var className = "Person";
//Define the constructor and method
var proto = {
constructor : function(name){=name;},
getName : function(){ return ;},
setName : function(name){ = name;}
}

//Define the class Person
(className,null,proto);

//Create an object
var p = new Person("tom");
(());//tom
("jack");
(());//jack

//Test the instanceof and whether it correctly points to Person
(p instanceof Person);//true
( === Person);//true