myundefinedvar shape = function (config) {
var that = {};
that.name = config.name || "";
that.area = function () {
return 0;
};
return that;};var rectangle = function (config, my) {
my = my || {};
my.l = config.length || 1;
my.w = config.width || 1;
var that = shape(config);
that.area = function () {
return my.l * my.w;
};
return that;};myShape = shape({
name: "Unhnown"});myRec = rectangle({
name: "Rectangle",
length: 4,
width: 6});console.log(myShape.name + " area is " + myShape.area() + " " + myRec.name + " area is " + myRec.area());沧海一幻觉
慕村225694
开满天机