Modifiers:
ctrl- Controloption- Option/Altcommand- Commandshift- Shift
Special keys:
→- Right Key←- Left Key↑- Up Key
| // Underscore.js isDefined mixin | |
| // Returns true if value is defined. | |
| _.mixin({ | |
| isDefined: function(reference) { | |
| return !_.isUndefined(reference); | |
| } | |
| }); | |
| /* Example: | |
| var obj = { |
| function(options) { | |
| options = _.defaults(options || {}, { | |
| index: 0, | |
| product: "sponge" | |
| }); | |
| } |
| +(NSString*)convertNSBezierPathToJSON:(NSBezierPath*)path { | |
| NSMutableArray* newPoints=[NSMutableArray array]; | |
| NSPoint points[3]; | |
| NSInteger numElements = [path elementCount]; | |
| for (int i = 0; i < numElements; i++) | |
| { | |
| NSBezierPathElement element=[path elementAtIndex:i associatedPoints:points]; | |
| switch (element) | |
| { |
Modifiers:
ctrl - Controloption - Option/Altcommand - Commandshift - ShiftSpecial keys:
→ - Right Key← - Left Key↑ - Up Key| // Converts JSON string to JavaScript Object. | |
| function jsonToObject(json) { | |
| var str=[[NSString alloc] initWithString:json]; | |
| return [NSJSONSerialization JSONObjectWithData:str.dataUsingEncoding(NSUTF8StringEncoding) options:0 error:nil]; | |
| } | |
| // Converts JavaScript Object to JSON string. | |
| function objectToJson(obj,prettyPrint) { | |
| var prettyPrint = prettyPrint || false; |
| var layer=selection.firstObject(); | |
| if(layer) { | |
| var TextBehaviour = { | |
| Auto: 0, | |
| Fixed: 1 | |
| }; | |
| layer.textBehaviour=TextBehaviour.Fixed; | |
| layer.frame().width=300; | |
| } |
Для того, чтобы грохнуть все ложные значения из масива, такие как false, ''(пустая строка), undefined, 0, null и NaN, в Underscore'e есть специальная функция _.compact(array). Функция возвращает копию поданного в нее массива без упомянутых ложных сообщений.
Может быть очень полезна в цепочки после вызова функции _.map(), которая в результате маппинга при определенных условиях может вернуть undefined, если нет надобности мапить обрабатываеммый объект.
Пример из документации:
_.compact([0, 1, false, 2, '', 3]);
=> [1, 2, 3]| import { createStore } from 'redux'; | |
| import _ from 'underscore'; | |
| const ADD_ITEM = 'ADD_ITEM'; | |
| const REMOVE_ITEM = 'REMOVE_ITEM'; | |
| const UPDATE_ITEM = 'UPDATE_ITEM'; | |
| const initialState = { | |
| items: [ | |
| { |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Hello World!</title> | |
| </head> | |
| <body> | |
| We are using Node.js <script>document.write(process.versions.node)</script>, | |
| Chromium <script>document.write(process.versions.chrome)</script>, | |
| and Electron <script>document.write(process.versions.electron)</script>. |