Пропустить теорию и перейти прямо к задачам
Ссылка на учебник: http://learn.javascript.ru
Сразу расскажу про несколько особенностей яваскрипта, о которых может быть не написано (или мало написано) в учебниках, но которые стоит понимать:
| <?php | |
| class ObjectSize { | |
| protected static $sizes = [ | |
| 'xxxxl', | |
| 'xxxl', | |
| 'xxl', | |
| 'xl', | |
| 'l', |
| /** | |
| * @param mixed $a | |
| * @param mixed $b | |
| * | |
| * @return int | |
| */ | |
| protected function _sortSizes($a, $b) | |
| { | |
| $aUpper = strtoupper($a); | |
| $bUpper = strtoupper($b); |
| import * as RNIap from 'react-native-iap'; | |
| RNIap. getPurchaseHistory().then((purchaseHistory) => { | |
| if(purchaseHistory.length > 0) { | |
| const getLastPurchase = purchaseHistory[purchaseHistory.length -1]; | |
| const getReceipt = getLastPurchase.transactionReceipt; | |
| // DO RECEIPT RELATED TASK | |
| } | |
| }); |
| //note: month is 0 based, just like Dates in js | |
| function getWeeksInMonth(month, year){ | |
| var weeks=[], | |
| firstDate=new Date(year, month, 1), | |
| lastDate=new Date(year, month+1, 0), | |
| numDays= lastDate.getDate(); | |
| var start=1; | |
| var end=7-firstDate.getDay(); | |
| while(start<=numDays){ |
| Got this issue today on windows, but don't need to downgrade node, just as discussed on stackoverflow just need to change some hashes on your project: | |
| \node_modules\metro-config\src\defaults\blacklist.js | |
| var sharedBlacklist = [ | |
| /node_modules[/\\]react[/\\]dist[/\\].*/, | |
| /website\/node_modules\/.*/, | |
| /heapCapture\/bundle\.js/, | |
| /.*\/__tests__\/.*/ | |
| ]; |
| // Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted: | |
| export const getLastItemInMap = map => Array.from(map)[map.size-1] | |
| export const getLastKeyInMap = map => Array.from(map)[map.size-1][0] | |
| export const getLastValueInMap = map => Array.from(map)[map.size-1][1] | |
| // Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity. |
| { | |
| "data": { | |
| "currentAge": 36.80011267063039, | |
| "yearsLeft": 43.607894089607434, | |
| "monthsLeft": 523.2947290752892, | |
| "daysLeft": 15927.783316229115, | |
| "hoursLeft": 382266.7995894988, | |
| "minutesLeft": 22936007.975369927, | |
| "secondsLeft": 1376160478.5221956, | |
| "dateString": "43 years 7 months 8 days 23 hours 17 minutes 42 seconds", |
| function declOfNum(number, titles) { | |
| cases = [2, 0, 1, 1, 1, 2]; | |
| return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
| } | |
| use: | |
| declOfNum(count, ['найдена', 'найдено', 'найдены']); |
| function getParent(snapshot) { | |
| // You can get the reference (A Firebase object) from a snapshot | |
| // using .ref(). | |
| var ref = snapshot.ref(); | |
| // Now simply find the parent and return the name. | |
| return ref.parent().name(); | |
| } | |
| var testRef = new Firebase("https://example.firebaseIO-demo.com/foo/bar"); | |
| testRef.once("value", function(snapshot) { |
Пропустить теорию и перейти прямо к задачам
Ссылка на учебник: http://learn.javascript.ru
Сразу расскажу про несколько особенностей яваскрипта, о которых может быть не написано (или мало написано) в учебниках, но которые стоит понимать: