当前位置:网站首页>Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
2022-07-03 23:46:00 【Xin Ran】
1. Source screenshot

- getObjectByProperty Method uses recursion
- getObjectById Methods and getObjectByProperty Methods are based on getObjectByProperty Method , So the core method of obtaining objects is getObjectByProperty
2. Code testing
Minor modifications : Put... In the source code this Change to pass more than one parameter , Convenient test , Because local is not object-oriented , The source code is object-oriented
// This method uses recursion
function
getObjectByProperty(
obj,
name,
value) {
if (
obj[
name]
===
value) {
// If there is a match , Will come here
return
obj;
}
for (
let
i
=
0,
l
=
obj.
children.
length;
i
<
l;
i
++) {
const
child
=
obj.
children[
i];
const
object
=
getObjectByProperty(
child,
name,
value);
if (
object
!==
undefined) {
return
object;
}
}
return
undefined;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
3. test
const
res
=
getObjectByProperty(
scene,
'name',
'mySphere')
- 1.
4. Core code description

5. summary
- The use of recursion
- Learn to read the source code , Learn others' coding ideas
边栏推荐
- [note] glide process and source code analysis
- [Happy Valentine's day] "I still like you very much, like sin ² a+cos ² A consistent "(white code in the attached table)
- Gorilla/mux framework (RK boot): add tracing Middleware
- Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~
- Tencent interview: can you pour water?
- After the Lunar New Year and a half
- Loop compensation - explanation and calculation of first-order, second-order and op amp compensation
- Docking Alipay process [pay in person, QR code Payment]
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- 2022.02.13
猜你喜欢

EPF: a fuzzy testing framework for network protocols based on evolution, protocol awareness and coverage guidance

Design of logic level conversion in high speed circuit

Recursive least square adjustment

A preliminary study on the middleware of script Downloader

Enter MySQL in docker container by command under Linux

Tencent interview: can you find the number of 1 in binary?

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
![[Happy Valentine's day]](/img/d9/9280398eb64907a567df6eea772adb.jpg)
[Happy Valentine's day] "I still like you very much, like sin ² a+cos ² A consistent "(white code in the attached table)

How to quickly build high availability of service discovery

How to make recv have a little temper?
随机推荐
Gorilla/mux framework (RK boot): add tracing Middleware
Selenium library 4.5.0 keyword explanation (II)
The difference between single power amplifier and dual power amplifier
Idea set class header comments
Sort merge sort
Idea integrates Microsoft TFs plug-in
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
Gossip about redis source code 81
Make small tip
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
D27:mode of sequence (maximum, translation)
[MySQL] sql99 syntax to realize multi table query
Docking Alipay process [pay in person, QR code Payment]
C # basic knowledge (1)
Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities
Schematic diagram of crystal oscillator clock and PCB Design Guide
Comment obtenir une commission préférentielle pour l'ouverture d'un compte en bourse? Est - ce que l'ouverture d'un compte en ligne est sécurisée?
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
X Opencv feature point detection and matching
SPI based on firmware library