Javascript面向對象編程——設計模式

function Box(name, age) { //不共享的使用構造函數 this.name = name; this.age = age; this.fruits = ['apple', 'banana', 'orange']; }; Box.prototype = { //共享的使用原型模式 constructor: Box, //強制指向Box run: function { return this.name + this.age + this.fruits; } }

相關推薦

推薦中...