ES6 - 字符串长度属性



原型属性允许你向任何对象(Number、Boolean、String、Date 等等)添加属性和方法。

注意 - 原型是全局属性,可用于几乎所有对象。

语法

string.prototype

示例:Object 原型

function employee(id, name) {
   this.id = id;
   this.name = name;
}
var emp = new employee(123, "Smith");
employee.prototype.email = "[email protected]";
console.log("Employee 's Id: " + emp.id);
console.log("Employee's name: " + emp.name);
console.log("Employee's Email ID: " + emp.email);

输出

Employee’s Id: 123
Employee’s name: Smith
Employee’s Email ID: [email protected]
广告