Prototype
优质
小牛编辑
129浏览
2023-12-01
prototype属性允许您向任何对象添加属性和方法(Number,Boolean,String,Date等)。
Note - Prototype是一个全局属性,几乎可用于所有对象。
语法 (Syntax)
string.prototype
示例:对象原型
function employee(id, name) {
this.id = id;
this.name = name;
}
var emp = new employee(123, "Smith");
employee.prototype.email = "smith@abc.com";
console.log("Employee 's Id: " + emp.id);
console.log("Employee's name: " + emp.name);
console.log("Employee's Email ID: " + emp.email);
输出 (Output)
Employee’s Id: 123
Employee’s name: Smith
Employee’s Email ID: smith@abc.com