const object = {
prop1: 'value1'
};
// https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
if (object.hasOwnProperty('prop1')) {
// your code here
}
// Тоже самое, что и 1й, но немного отличается своей работой
// https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty#Example_hasOwnProperty_as_a_property
if (Object.prototype.hasOwnProperty.call(object, 'prop1')) {
// your code here
}
if (object.prop1) {
// your code here
}
if (typeof object.prop1 !== 'undefined') {
// your code here
}
if ('prop1' in object) {
// your code here
}
const mapStateToProps = ({ user, data }) => {
const myProp = localStorage.get('myProp');
return {
myProp,
user,
data
}
};
const mapStateToProps = props => props;
// api.js
import axios from 'axios';
const API = axios.create({
baseURL: 'https://mysite.com/api',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.TOKEN,
},
withCredentials: true,
});
API.interceptors.response.use(response => {
console.log('yeeeeeeeeeeeeeeeeeeeeeeeee');
console.log(response);
return response;
}, error => {
console.log('fuuuuuuuuuuuu');
console.log(error);
return Promise.reject(error);
});
export default API
// services/cart.js
import API from 'api'
export default {
async getCart () {
const { data } = await API.get('/cart')
}
}
// services/catalog.js
import API from 'api'
export default {
async getCatalog () {
const { data } = await API.get('/catalog')
}
}
// main.js
import { getCatalog } from 'services/catalog'
import { getCart } from 'services/cart'
async (() => {
await Promise.all([
getCatalog(),
getCart()
])
})();
try {
const response = await Promise.all(map(list, ({address}) => ymaps.geocode(`address`)))
const coordinates = map(response, (coordinate) => coordinate.geoObjects.get(0).geometry.getCoordinates());
allCoordinates.push(...coordinates);
} catch (error) {
this.props.onError();
}