:
if (angular.isObject(place) && place.hasOwnProperty('opening_hours')) {
var openingHours = place.opening_hours;
if (angular.isObject(openingHours) && openingHours.hasOwnProperty('weekday_text')) {
$scope.input.opening_hours = openingHours.weekday_text;
}
else {
$scope.input.opening_hours = '';
}
}
else {
$scope.input.opening_hours = '';
}
순수와 JS :
// check if a object value
function isObject (_object) {
return Object.keys(_object).length >= 0 && _object.constructor === Object
}
if (isObject(place) && place.hasOwnProperty('opening_hours')) {
var openingHours = place.opening_hours;
if (isObject(openingHours) && openingHours.hasOwnProperty('weekday_text')) {
$scope.input.opening_hours = openingHours.weekday_text;
}
else {
$scope.input.opening_hours = '';
}
}
else {
$scope.input.opening_hours = '';
}
pathExists JS (기본) 사용 : 삼원
if (objectPathExists(place, 'opening_hours.weekday_text')) {
$scope.input.opening_hours = openingHours.weekday_text;
} else {
$scope.input.opening_hours = '';
}
:
$scope.input.opening_hours = objectPathExists(place, 'opening_hours.weekday_text') ? openingHours.weekday_text : ''
pathExists JS (프로토 타입)을 사용하여 53,691,363,210
:
if (place.pathExists('opening_hours.weekday_text')) {
$scope.input.opening_hours = openingHours.weekday_text;
} else {
$scope.input.opening_hours = '';
}
삼항 : 나는 의견을 알려으로
$scope.input.opening_hours = place.pathExists('opening_hours.weekday_text') ? openingHours.weekday_text : ''
opening_hours는 – Mahi
내가 연산자 우선 순위가 예상 무슨 다른 생각 정의되지 않은, 당신은 실제로 실행중인 : $ scope.input.opening_hours = place.opening_hours && (place.opening_hours.weekday_text place.opening_hours.weekday_text : '';) –
괄호를 사용하십시오. 그러나 나는 왜 당신이 그 일을해야하는지 이해할 수 없다. 원래의'if()'를 더 잘 읽을 수있다. –