In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the ways in which Objects creates objects?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Data Structures
Data Types: numbers, strings, booleans and arrays.
Boolean
If it is not set, or if it is set to false, "", "false,undefined,NaN", or "true", otherwise it is set to "true".
Arrays
Var myCars=new Array (); var myCars=new Array ("Saab", "Volvo", "BMW"); var myCars= ["Saab", "Volvo", "BMW"]
Objects
There are two ways to create objects
(1) object literal notation
Var myObj = {type: 'fancy',age:24, speak: function () {} / / method}
(2) object constructor
Var myObj = new Object (); / / using a built-in constructor called ObjectmyObj ["name"] = "Charlie"; myObj.name = "Charlie"
Custom constructor
Function Rabbit (adjective) {this.adjective = adjective; var age=12; / / private cannot modify this.describeMyself = function () {console.log ("I am a" + this.adjective + "rabbit");};} var rabbit1 = new Rabbit ("fluffy"); / / className.prototype.newMethod = function () {} add method Rabbit.prototype.describeMyself = function () {} Object Oriented to a class
Inherit
/ the original Animal class and sayName methodfunction Animal (name, numLegs) {this.name = name; this.numLegs = numLegs;} Animal.prototype.sayName = function () {console.log ("Hi my name is" + this.name);}; / / define a Penguin classfunction Penguin (name) {this.name = name; this.numLegs = 2;} / / set its prototype to be a new instance of AnimalPenguin.prototype = new Animal (); var p = new Penguin ("Timmy"); p.sayName ()
Custom declared classes inherit from the Object class
/ / Object.prototype itself is an object// what is this "Object.prototype" anyway...?var prototypeType = typeof Object.prototype;console.log (prototypeType); / / object// now let's examine itinervar hasOwn = Object.prototype.hasOwnProperty ("hasOwnProperty"); console.log (hasOwn); / / true
Privatized members and methods
/ * Public properties can be accessed from outside the classPrivate properties can only be accessed from within the class*/function Person (first,last,age) {this.firstname = first; this.lastname = last; this.age = age; var bankBalance = 7500; / / var this.bankBalance (no this) var returnBalance = function () {return bankBalance;}; / / create the new function here this.askTeller = function () {return returnBalance }} var john = new Person ('John','Smith',30); console.log (john.returnBalance); var myBalanceMethod = john.askTeller (); var myBalance = myBalanceMethod (); console.log (myBalance); "how Objects creates objects" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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: 0
*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.