当前位置:网站首页>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
边栏推荐
- [issue 16] golang's one-year experience in developing Purdue Technology
- leetcode-43. String multiplication
- D24:divisor and multiple (divisor and multiple, translation + solution)
- QT creator source code learning note 05, how does the menu bar realize plug-in?
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- JDBC Technology
- Enter MySQL in docker container by command under Linux
- Introducing Software Testing
- Selenium library 4.5.0 keyword explanation (III)
- Amway by head has this project management tool to improve productivity in a straight line
猜你喜欢

Scratch uses runner Py run or debug crawler
![[note] IPC traditional interprocess communication and binder interprocess communication principle](/img/f6/36c28df02198539e27352e3cdf4ba6.jpg)
[note] IPC traditional interprocess communication and binder interprocess communication principle

Unity shader visualizer shader graph

Idea a method for starting multiple instances of a service

JDBC Technology

2022.02.14

Common mode interference of EMC

QT creator source code learning note 05, how does the menu bar realize plug-in?

Fluent learning (4) listview

Hcip day 14 notes
随机推荐
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
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?
Maxwell equation and Euler formula - link
Qtoolbutton - menu and popup mode
MLX90614 driver, function introduction and PEC verification
Smart fan system based on stm32f407
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe
ADB related commands
Gossip about redis source code 76
[MySQL] sql99 syntax to realize multi table query
NPM script
Alibaba cloud container service differentiation SLO hybrid technology practice
What is the Valentine's Day gift given by the operator to the product?
Fashion cloud interview questions series - JS high-frequency handwritten code questions
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
ADB command to get XML
2022.02.13
D24:divisor and multiple (divisor and multiple, translation + solution)
Esp-idf turns off serial port log output.