Because the three variables are all geometry fields, it would probably make the most sense to use an object rather than three standalone variables:
const geometryFields = {
Point: $('[class*="Point"]', $panel),
Line: $('[class*="Line"]', $panel),
Polygon: $('[class*="Polygon"]', $panel)
};
Then you can access the property of the object with the geometry
string:
function showGeom(classStr) {
geometryFields[classStr].show();
}
If you have to use standalone variables, you could eval
, but you really shouldn't eval
:
$geometryPointFields = $('.point');
function showGeom(classStr) {
eval('$geometry' + classStr + 'Fields').show();
}
setTimeout(() => showGeom('Point'), 1500);
.point { display: none }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="point">point</div>