In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "JavaScript flexibility example Analysis". In daily operation, I believe many people have doubts about JavaScript flexibility example analysis. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "JavaScript flexibility example Analysis". Next, please follow the editor to study!
First, deploy an add method on the Number.prototype object.
Number.prototype.add = function (x) {return this + x;}
The above code defines an add method for an instance of Number. If you are not familiar with this way of writing, it is recommended to read my "JavaScript object-oriented programming" first. )
Because an instance of Number is a numeric value, if you call a method on a numeric value, the value is automatically converted to an instance object, so you get the following result.
8 ['add'] (2) / / 10
In the above code, the calling method is written as 8 ['add'] instead of 8. Add because the point after the value is interpreted as a decimal point rather than a point operator.
By placing the value in parentheses, you can use the point operator to call the method.
(8) .add (2) / / 10
In fact, there is another way to write it.
8..add (2) / / 10
The * points in the above code are interpreted as decimal points, and the second point is interpreted as the dot operator. For the sake of semantic clarity, I will uniformly use parentheses below.
Because the add method returns a numeric value, it can be chained.
Number.prototype.subtract = function (x) {return this-x;}; (8) .add (2) .subtract (4) / / 6
The above code deploys the subtract method on an instance of the Number object, which can be called chained with the add method.
If you use square brackets to call a property, it can be written in an odd way.
8 ["add"] (2) ["subtract"] (4) / / 6
We can also deploy more complex methods.
Number.prototype.iterate = function () {var result = []; for (var I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 206
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.