This 2 paragraph about the JavaScript functional mode "Modular mode" of the summary, but also need to carefully ponder!!!

Source: Internet
Author: User

<script>
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
This.prototype[name] = func;
}
};
Object.Method (' Superior ', function (name) {
var = this,
method = That[name];
return function () {
Return method.apply (that, arguments);
};
});
var mammal = function (spec) {
var that = {};
That.get_name = function () {
return spec.name;
};
That.says = function () {
return Spec.saying | | ‘‘;
};
return that;
};
var mymammal = mammal ({name: ' Herb '});
var cat = function (spec) {
spec.saying = Spec.saying | | ' Meow ';
var that = mammal (spec);
That.purr = function (n) {
var i, s = ';
for (i = 0; i < n; i + = 1) {
if (s) {
s + = '-';
}
s + = ' r ';
}
return s;
};
That.get_name = function () {
return that.says () + ' + Spec.name +
"+ that.says ();
}
return that;
};
var Mycat = Cat ({name: ' Henrietta '});
var Coolcat = function (spec) {
var that = Cat (spec),
Super_get_name = That.superior (' get_name ');
That.get_name = function (n) {
Return ' like ' + super_get_name () + ' baby ';
};
return that;
};

var mycoolcat = Coolcat ({name: ' Bix '});
var name = Mycoolcat.get_name ();
' Like meow Bix meow Baby '

</script>
<script>
function Createcar (numberofdoors) {
var numberofwheels = 4;
function describe () {
Return "I have" + Numberofwheels + "wheels and" + numberofdoors + "doors.";
}
return {
Describe:describe
};
}
function Createodometer () {
var mileage = 0;
function Increment (numberofmiles) {mileage + = Numberofmiles;}
Function report () {return mileage;}
return {
Increment:increment,
Report:report
}
}

function Createcarwithodometer (numberofdoors) {
var odometer = Createodometer ();
var car = Createcar (numberofdoors);
car.drive = function (numberofmiles) {
Odometer.increment (Numberofmiles);
}
Car.mileage = function () {
Return "car has driven" + odometer.report () + "Miles";
}
return car;
}


var twofn=createcarwithodometer (100);


Console.log (TWOFN);

</script>

This 2 paragraph about the JavaScript functional mode "Modular mode" of the summary, but also need to carefully ponder!!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.