当前位置:网站首页>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
边栏推荐
- Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place
- Arc135 partial solution
- How will the complete NFT platform work in 2022? How about its core functions and online time?
- Les sociétés de valeurs mobilières dont la Commission d'ouverture d'un compte d'actions est la plus faible ont ce que tout le monde recommande.
- URLEncoder. Encode and urldecoder Decode processing URL
- "Learning notes" recursive & recursive
- Tencent interview: can you pour water?
- The difference between single power amplifier and dual power amplifier
- Common mode interference of EMC
- D27:mode of sequence (maximum, translation)
猜你喜欢

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Hcip day 16 notes

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

Introducing Software Testing

Pyqt5 sensitive word detection tool production, operator's Gospel

Interesting 10 CMD commands

How to write a good title of 10w+?

It is forbidden to splice SQL in code

Zipper table in data warehouse (compressed storage)

How to prevent malicious crawling of information by one-to-one live broadcast source server
随机推荐
After the Lunar New Year and a half
Hcip 13th day notes
IO flow principle and classification
Selenium library 4.5.0 keyword explanation (III)
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
"Learning notes" recursive & recursive
Sword finger offer day 4 (Sword finger offer 03. duplicate numbers in the array, sword finger offer 53 - I. find the number I in the sorted array, and the missing numbers in sword finger offer 53 - ii
炒股開戶傭金優惠怎麼才能獲得,網上開戶安全嗎
Selenium library 4.5.0 keyword explanation (II)
Go error collection | talk about the difference between the value type and pointer type of the method receiver
D28:maximum sum (maximum sum, translation)
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Selenium library 4.5.0 keyword explanation (4)
Recursive least square adjustment
Alibaba cloud container service differentiation SLO hybrid technology practice
A preliminary study on the middleware of script Downloader
D23:multiple of 3 or 5 (multiple of 3 or 5, translation + solution)
Hcip day 15 notes
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-