├── .editorconfig ├── .gitignore ├── .npmrc ├── .travis.yml ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── index.js ├── locale │ ├── bg.js │ ├── cz.js │ ├── de.js │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── id.js │ ├── index.js │ ├── it.js │ ├── nl.js │ ├── pt_pt.js │ ├── ru.js │ ├── zh_cn.js │ └── zh_hk.js ├── options.js └── store │ ├── bg.js │ ├── cz.js │ ├── de.js │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── id.js │ ├── index.js │ ├── it.js │ ├── nl.js │ ├── pt_pt.js │ ├── ru.js │ ├── zh_cn.js │ └── zh_hk.js └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,.*rc,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ademola Adegbuyi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | object-explorer-cli 3 |

4 |

5 | Object Explorer CLI 6 | npm travis 7 |

8 |

Find the object method you need without digging through the docs.

9 | 10 | ## Installation 11 | 12 | ```sh 13 | npm i -g object-explorer-cli 14 | ``` 15 | 16 | ## Usage 17 | 18 | Open your CLI and type: 19 | ```sh 20 | object-explorer 21 | ``` 22 | or 23 | ```sh 24 | obj-explorer 25 | ``` 26 | and feel the magic :star: 27 | 28 | object-explorer-cli 29 | 30 | You should also check out [Array Explorer CLI](https://github.com/ooade/array-explorer-cli) 31 | 32 | ## Available Options 33 | 34 | - **-help** - displays help 35 | - **-lang=\ | -l \** - displays object-explorer in the specified language code 36 | 37 | ## List of Available Languages 38 | 39 | | Short Code | Language | 40 | | - | - | 41 | |bg|Bulgarian| 42 | |cz|Czech| 43 | |de|German| 44 | |en|English(Default)| 45 | |es|Spanish| 46 | |fr|French| 47 | |id|Indonesian| 48 | |it|Italian| 49 | |nl|Dutch| 50 | |pt_pt|Portuguese (Portugal)| 51 | |ru|Russian| 52 | |zh_cn|Chinese (Simplified)| 53 | |zh_hk|Chinese (Traditional)| 54 | 55 | Create an issue to add more :tada: 56 | 57 | ## Aknowledgements 58 | Thanks to [Sarah Drasner](https://github.com/sdras). She created the [object-explorer](https://github.com/sdras/object-explorer) web version which you could visit using https://sdras.github.io/object-explorer/ 59 | 60 | ## Contributions 61 | Feel free to contribute. 62 | 63 | ## License 64 | MIT -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "object-explorer-cli", 3 | "version": "0.2.0", 4 | "description": "Find the object method you need without digging through the docs", 5 | "main": "./src/index.js", 6 | "author": "Ademola Adegbuyi ", 7 | "bin": { 8 | "object-explorer": "./src/index.js", 9 | "obj-explorer": "./src/index.js" 10 | }, 11 | "scripts": { 12 | "test": "node ./test.js | tap-spec" 13 | }, 14 | "license": "MIT", 15 | "dependencies": { 16 | "chalk": "^2.3.2", 17 | "clear": "^0.1.0", 18 | "figlet": "^1.2.0", 19 | "inquirer": "^5.1.0", 20 | "minimist": "^1.2.0" 21 | }, 22 | "devDependencies": { 23 | "tap-spec": "^4.1.1", 24 | "tape": "^4.9.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const inquirer = require('inquirer') 4 | const figlet = require('figlet') 5 | const clear = require('clear') 6 | const chalk = require('chalk') 7 | const argv = require('minimist')(process.argv.slice(2)) 8 | 9 | clear() 10 | 11 | const lang = 12 | typeof argv.lang === 'string' 13 | ? argv.lang 14 | : typeof argv.l === 'string' ? argv.l : 'en' 15 | 16 | const help = argv.help || argv.h || argv._[0] === 'help' 17 | 18 | console.log(figlet.textSync('{ } Explorer')) 19 | 20 | if (help) { 21 | const countryCodeWithLanguage = `|bg|Bulgarian| 22 | |cz|Czech| 23 | |de|German| 24 | |en|English(Default)| 25 | |es|Spanish| 26 | |fr|French| 27 | |id|Indonesian| 28 | |it|Italian| 29 | |nl|Dutch| 30 | |pt_pt|Portuguese (Portugal)| 31 | |ru|Russian| 32 | |zh_cn|Chinese (Simplified)| 33 | |zh_hk|Chinese (Traditional)|` 34 | 35 | console.log() 36 | 37 | console.log( 38 | '- A CLI package to help figure out what JavaScript object method would be best to use at any given time' 39 | ) 40 | 41 | console.log() 42 | 43 | console.log( 44 | `${chalk.bold('usage:')} object-explorer [help] [-h | --help] ` 45 | ) 46 | 47 | console.log() 48 | 49 | console.log(' can be one of the following:') 50 | 51 | console.log() 52 | 53 | countryCodeWithLanguage 54 | .split('\n') 55 | .map(s => s.split('|').slice(1, 3)) 56 | .map(([code, lang]) => { 57 | console.log(`- ${chalk.bold(code)} - ${chalk.hex('#888888')(lang)}`) 58 | }) 59 | 60 | console.log() 61 | 62 | console.log('Example: object-explorer --lang es') 63 | 64 | console.log() 65 | 66 | return 67 | } 68 | 69 | let questions = require('./options')(lang) 70 | let state = require('./store')[lang].state 71 | 72 | console.log() 73 | 74 | inquirer.prompt(questions).then(answers => { 75 | let answer = Object.keys(answers).filter(answer => answer !== 'init') 76 | 77 | // This arr stores the container of our real answer 78 | let arr = [] 79 | 80 | // if 2, it's an obj, walk through it 81 | if (answer.length === 2) { 82 | arr = state[answer[0]][answer[1]] 83 | } else { 84 | arr = state[answer[0]] 85 | } 86 | 87 | const objValue = Object.keys(answers).map(answer => answers[answer]) 88 | 89 | const value = arr.filter(item => item.shortDesc === objValue.slice(-1)[0])[0] 90 | 91 | const formatCode = str => 92 | str 93 | .replace(/\n+\t+/g, '\t') 94 | .replace(/
/g, '\n') 95 | .replace(/\\ \;\ \;\<\/span\>/g, '\t') 96 | .replace(/\]*\>(.*?)\<\/span\>/g, (_, s) => chalk.hex('#888')(s)) 97 | 98 | const formatDesc = str => 99 | str 100 | .replace(/\n+\t+/g, '') 101 | .replace(/\(.*?)\<\/code\>/g, (_, s) => chalk.bold(s)) 102 | .replace(/\(.*?)\<\/strong\>/g, (_, s) => chalk.bold(s)) 103 | .replace(/\/g, '\n') 104 | 105 | console.log() 106 | 107 | console.log(chalk.green.bold(`Object.${value.name}()`)) 108 | 109 | console.log() 110 | 111 | console.log('- ' + formatDesc(value.desc)) 112 | 113 | console.log() 114 | 115 | console.log(chalk.bold('USAGE:')) 116 | 117 | console.log( 118 | chalk.hex('#aeded4')('\tlet obj = {\n\t a: 1,\n\t b: 2,\n\t c: 3 \n\t};\n') 119 | ) 120 | 121 | console.log('\t' + chalk.hex('#aeded4')(formatCode(value.example))) 122 | 123 | console.log() 124 | 125 | console.log( 126 | chalk.bold('OUTPUT:\t') + chalk.hex('#ecc2a4')(formatCode(value.output)) 127 | ) 128 | 129 | console.log() 130 | 131 | console.log( 132 | chalk.bold('READ MORE: ') + 133 | 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/' + 134 | value.name 135 | ) 136 | 137 | console.log() 138 | }) 139 | -------------------------------------------------------------------------------- /src/locale/bg.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Имам обект, бих искал да', 3 | infoPropMethod: 'Искам да взема', 4 | methodOptions: 'Искам да', 5 | methodTypes: { 6 | create: 'създам', 7 | determine: 'определя', 8 | 'return a': 'върна', 9 | 'find out': 'намеря', 10 | 'get an array of all of the': 'получа масив от всички' 11 | // string: 'string' 12 | }, 13 | details: 'допълнителна информация за свойството', 14 | list: 'списък от всички ключове и/или стойности', 15 | primaryOptions: [ 16 | 'създам обект', 17 | 'създам свойства', 18 | 'получа информация за обект', 19 | 'получа информация за свойства', 20 | 'огранича промени по обект', 21 | 'създам низ от даден обект', 22 | 'управлявам прототипите' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/cz.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Maám objekt a chci', 3 | infoPropMethod: 'Potřebuji získat', 4 | methodOptions: 'Potřebuji', 5 | methodTypes: { 6 | create: 'vytvořit', 7 | determine: 'zjistit', 8 | 'return a': 'vrátit', 9 | 'find out': 'zjistit', 10 | 'get an array of all of the': 'získat pole všech' 11 | // string: 'string' 12 | }, 13 | details: 'podrobnosti o vlastnosti', 14 | list: 'seznam všech klíčů anebo hodnot', 15 | primaryOptions: [ 16 | 'vytvořit objekt', 17 | 'vytvořit vlastnost', 18 | 'získat informaci o objektu', 19 | 'získat informaci o vlastnosti', 20 | 'omezit změny pro objekt', 21 | 'vytvořit řetězec z objektu', 22 | 'spravovat prototypy' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/de.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: "Ich habe ein Objekt und würde gerne", 3 | infoPropMethod: "Ich benötige", 4 | methodOptions: "Ich möchte", 5 | methodTypes: { 6 | create: "hinzufügen", 7 | determine: "feststellen", 8 | "return a": "zurückgeben", 9 | "find out": "herausfinden", 10 | "get an array of all of the": "ein Array mit allen" 11 | // string: 'string' 12 | }, 13 | details: "Details über eine Eigenschaft", 14 | list: "eine Liste aller Eigenschaften und/oder Werte", 15 | primaryOptions: [ 16 | "ein Objekt erstellen", 17 | "Eigenschaften erstellen", 18 | "Informationen über ein Objekt erhalten", 19 | "Informationen über Eigenschaften erhalten", 20 | "Änderungensmöglichkeiten einschränken", 21 | "einen String von einem Objekt erstellen", 22 | "Eigenschaften verwalten" 23 | ] 24 | // other text can be added here 25 | }; 26 | -------------------------------------------------------------------------------- /src/locale/en.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'I have an object, I would like to', 3 | infoPropMethod: 'I need to get', 4 | methodOptions: 'I need to', 5 | methodTypes: { 6 | create: 'create', 7 | determine: 'determine', 8 | 'return a': 'return a', 9 | 'find out': 'find out', 10 | 'get an array of all of the': 'get an array of all of the' 11 | // string: 'string' 12 | }, 13 | details: 'details about the property', 14 | list: 'a list of all of the keys and/or values', 15 | primaryOptions: [ 16 | 'create an object', 17 | 'create properties', 18 | 'get information about an object', 19 | 'get information about properties', 20 | 'restrict changes to an object', 21 | 'create a string from an object', 22 | 'manage prototypes' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/es.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Tengo un objeto, me gustaría', 3 | infoPropMethod: 'Necesito conseguir', 4 | methodOptions: 'Necesito', 5 | methodTypes: { 6 | create: 'crear', 7 | determine: 'determinar', 8 | 'return a': 'devolver un', 9 | 'find out': 'averiguar', 10 | 'get an array of all of the': 'conseguir un array de todos los' 11 | // string: 'string' 12 | }, 13 | details: 'detalles de la propiedad', 14 | list: 'una lista de todas las claves y/o valores', 15 | primaryOptions: [ 16 | 'crear un objeto', 17 | 'crear propiedades', 18 | 'obtener informacio de los objetos', 19 | 'obtener informacion de las propiedades', 20 | 'restringir cambios en un objeto', 21 | 'crear una cadena desde un objeto', 22 | 'manejar prototipos' 23 | ] 24 | // other text can be added here 25 | } -------------------------------------------------------------------------------- /src/locale/fr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: "J'ai un objet, je veux", 3 | infoPropMethod: 'Je veux obtenir', 4 | methodOptions: 'Je veux', 5 | methodTypes: { 6 | create: 'créer', 7 | determine: 'déterminer', 8 | 'return a': 'obtenir', 9 | 'find out': 'trouver', 10 | 'get an array of all of the': 'obtenir un array de tous/toutes les' 11 | // string: 'string' 12 | }, 13 | details: 'des détails sur la propriété', 14 | list: 'une liste de toutes les propriétés et/ou valeurs', 15 | primaryOptions: [ 16 | 'créer un objet', 17 | 'créer des propritétés', 18 | 'obtenir des informations sur un objet', 19 | 'obtenir des informations sur les propriétés', 20 | 'restreindre les modifications sur un objet', 21 | "créer une chaîne de caractères à partir d'un objet", 22 | 'gérer les prototypes' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Saya mempunyai objek, saya ingin', 3 | infoPropMethod: 'Saya ingin mendapatkan', 4 | methodOptions: 'Saya ingin', 5 | methodTypes: { 6 | create: 'membuat', 7 | determine: 'menentukan', 8 | 'return a': 'mengembalikan sebuah', 9 | 'find out': 'menemukan', 10 | 'get an array of all of the': 'mendapatkan sebuah array dari semua' 11 | // string: 'string' 12 | }, 13 | details: 'detil tentang properti', 14 | list: 'daftar dari seluruh kunci dan/atau nilai', 15 | primaryOptions: [ 16 | 'membuat sebuah objek', 17 | 'membuat properti', 18 | 'mendapatkan informasi tentang sebuah objek', 19 | 'mendapatkan informasi tentang properti', 20 | 'membatasi perubahan terhadap sebuah objek', 21 | 'membuat sebuah string dari sebuah objek', 22 | 'mengatur prototipe' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bg: require('./bg'), 3 | cz: require('./cz'), 4 | de: require('./de'), 5 | en: require('./en'), 6 | es: require('./es'), 7 | fr: require('./fr'), 8 | id: require('./id'), 9 | it: require('./it'), 10 | nl: require('./nl'), 11 | pt_pt: require('./pt_pt'), 12 | ru: require('./ru'), 13 | zh_cn: require('./zh_cn'), 14 | zh_hk: require('./zh_hk') 15 | } 16 | -------------------------------------------------------------------------------- /src/locale/it.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Ho un oggetto e vorrei', 3 | infoPropMethod: 'Ho bisogno di ottenere', 4 | methodOptions: 'Ho bisogno di', 5 | methodTypes: { 6 | create: 'creare', 7 | determine: 'sapere se', 8 | 'return a': 'generare', 9 | 'find out': 'sapere', 10 | 'get an array of all of the': 'un array che contenga' 11 | }, 12 | details: 'dettagli riguardo delle proprietà', 13 | list: 'una lista di tutte le chiavi e/o valori', 14 | primaryOptions: [ 15 | 'crearne uno nuovo', 16 | 'definire delle proprietà', 17 | 'ottenere informazioni riguardo ad esso', 18 | 'ottenere informazioni riguardo le sue proprietà', 19 | 'proteggerlo da alcuni cambiamenti', 20 | 'creare una stringa che lo rappresenti', 21 | 'gestirne il prototipo' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/nl.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Ik heb een object, ik wil graag', 3 | infoPropMethod: 'Ik heb nodig', 4 | methodOptions: 'Ik moet', 5 | methodTypes: { 6 | create: 'aanmaken', 7 | determine: 'bepalen', 8 | 'return a': 'teruggeven', 9 | 'find out': 'er achter komen', 10 | 'get an array of all of the': 'een array krijgen van alle' 11 | // string: 'string' 12 | }, 13 | details: 'details over de property', 14 | list: 'een lijst van alle keys en/of waardes', 15 | primaryOptions: [ 16 | 'een object aanmaken', 17 | 'properties aanmaken', 18 | 'informatie krijgen over een object', 19 | 'informatie krijgen over properties', 20 | 'veranderingen aan een object beperken', 21 | 'van een object een string maken', 22 | 'prototypes beheren' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/pt_pt.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Eu tenho um objecto e gostaria de', 3 | infoPropMethod: 'Preciso de obter', 4 | methodOptions: 'Preciso de', 5 | methodTypes: { 6 | create: 'criar', 7 | determine: 'determinar', 8 | 'return a': 'retornar', 9 | 'find out': 'descobrir', 10 | 'get an array of all of the': 'obter uma array de todos os' 11 | // string: 'string' 12 | }, 13 | docsLink: 'Ver Documentação', 14 | details: 'detalhes sobre a propriadade', 15 | list: 'a lista de todas as keys e/ou valores', 16 | primaryOptions: [ 17 | 'criar um objecto', 18 | 'criar propriadades', 19 | 'receber informações sobre um objecto', 20 | 'receber informações sobre as propriadades', 21 | 'restringir mudanças a um objecto', 22 | 'criar texto aparatir de um objecto', 23 | 'gerir protótipos' 24 | ] 25 | // other text can be added here 26 | } 27 | -------------------------------------------------------------------------------- /src/locale/ru.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'У меня есть объект, я хотел бы', 3 | infoPropMethod: 'Мне нужно получить', 4 | methodOptions: 'Мне нужно', 5 | methodTypes: { 6 | create: 'создать', 7 | determine: 'определить', 8 | 'return a': 'вернуть', 9 | 'find out': 'узнать', 10 | 'get an array of all of the': 'получить массив всех' 11 | // string: 'string' 12 | }, 13 | details: 'информацию о свойстве', 14 | list: 'список всех ключей и/или значений', 15 | primaryOptions: [ 16 | 'создать объект', 17 | 'создать свойство', 18 | 'получить информацию об объекте', 19 | 'получить информацию о свойстве', 20 | 'ограничить возможность изменения объекта', 21 | 'сформировать строку из объекта', 22 | 'управлять поведением прототипов' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/zh_cn.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: '我有一个对象,我想', 3 | infoPropMethod: '我需要获得', 4 | methodOptions: '我需要', 5 | methodTypes: { 6 | create: '创建', 7 | determine: '检查', 8 | 'return a': '返回一个', 9 | 'find out': '知道', 10 | 'get an array of all of the': '一个数组,包含对象的所有' 11 | // string: 'string' 12 | }, 13 | details: '关于属性的详细信息', 14 | list: '所有键和/或值的列表', 15 | primaryOptions: [ 16 | '创建一个对象', 17 | '创建属性', 18 | '获得关于对象的信息', 19 | '获得关于属性的信息', 20 | '限制对象的改变', 21 | '根据一个对象得到字符串', 22 | '管理原型' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/locale/zh_hk.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: '我有一個物件,我想', 3 | infoPropMethod: '我需要獲得', 4 | methodOptions: '我需要', 5 | methodTypes: { 6 | create: '建立', 7 | determine: '檢查', 8 | 'return a': '返回一個', 9 | 'find out': '找出', 10 | 'get an array of all of the': '獲取陣列來自' 11 | // string: 'string' 12 | }, 13 | details: '關於屬性的詳情資料', 14 | list: '所有鍵值和/或值的列表', 15 | primaryOptions: [ 16 | '建立一個物件', 17 | '建立屬性', 18 | '獲取物件的資料', 19 | '獲取屬性的資料', 20 | '限制對物件作出改變', 21 | '由物件建立字串', 22 | '管理原型' 23 | ] 24 | // other text can be added here 25 | } 26 | -------------------------------------------------------------------------------- /src/options.js: -------------------------------------------------------------------------------- 1 | const locale = require('./locale') 2 | 3 | // Maps method to primary option index 4 | const mapMethodToIndex = { 5 | createObj: 0, 6 | createProp: 1, 7 | infoObj: 2, 8 | noChange: 4, 9 | createString: 5, 10 | infoProp: 3, 11 | prototype: 6 12 | } 13 | 14 | function singleOption(type, name, message, choices, when) { 15 | return { 16 | type, 17 | name, 18 | message, 19 | choices, 20 | when 21 | } 22 | } 23 | 24 | const capitalize = str => str[0].toUpperCase() + str.slice(1) 25 | 26 | function generateOptions(lang) { 27 | let localeLang = locale[lang] 28 | 29 | if (!Object.keys(locale).some(l => l === lang)) { 30 | console.log() 31 | 32 | console.log('Language not found!') 33 | 34 | console.log() 35 | 36 | console.log( 37 | 'Type `object-explorer help` to see list of available languages' 38 | ) 39 | 40 | console.log() 41 | 42 | process.exit(1) 43 | } 44 | 45 | const state = require('./store')[lang].state 46 | 47 | // This has the localMethods names 48 | const localeMethods = Object.keys(state).slice(1) 49 | 50 | // The first option that is shown to users 51 | const firstOption = [ 52 | { 53 | type: 'list', 54 | name: 'init', 55 | message: localeLang.firstMethod, 56 | choices: localeLang.primaryOptions 57 | } 58 | ] 59 | 60 | // Picks the methodVerbs 61 | const methodVerbs = { 62 | createObj: '', 63 | createProp: localeLang.methodTypes.create, 64 | infoObj: localeLang.methodTypes.determine, 65 | noChange: '', 66 | createString: localeLang.methodTypes['return a'], 67 | infoProp: localeLang.infoPropMethod, 68 | infoPropList: localeLang.methodTypes['get an array of all of the'], 69 | infoPropDetails: localeLang.methodTypes['find out'], 70 | prototype: '' 71 | } 72 | 73 | const options = localeMethods.map(method => { 74 | const methodIndex = mapMethodToIndex[method] 75 | const methodVerb = methodVerbs[method] 76 | 77 | let methodOptions = localeLang.methodOptions 78 | let choices 79 | 80 | if (method === 'infoProp') { 81 | choices = [localeLang.details, localeLang.list] 82 | methodOptions = localeLang.infoPropMethod 83 | } else { 84 | choices = state[method].map(s => s.shortDesc) 85 | } 86 | 87 | return singleOption( 88 | 'list', 89 | method.trim(), 90 | (method === 'infoProp' 91 | ? methodVerb 92 | : methodOptions + ' ' + methodVerb 93 | ).trim(), 94 | choices, 95 | answers => answers.init === localeLang.primaryOptions[methodIndex] 96 | ) 97 | }) 98 | 99 | return firstOption.concat( 100 | options.concat( 101 | Object.keys(state.infoProp).map(method => { 102 | return singleOption( 103 | 'list', 104 | method, 105 | localeLang.methodOptions + 106 | ' ' + 107 | methodVerbs['infoProp' + capitalize(method)], 108 | state.infoProp[method].map(s => s.shortDesc), 109 | answers => answers.infoProp === localeLang[method] 110 | ) 111 | }) 112 | ) 113 | ) 114 | } 115 | 116 | module.exports = generateOptions 117 | -------------------------------------------------------------------------------- /src/store/bg.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'създам нов обект', 8 | desc: `Създава нов обект със зададения прототип и свойства.
9 |
10 | Важно за начинаещи! Създаването на обект по начина показан в началото на примера е по-често срещано, например така: let obj = { a: 1 };`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'направя копие на обект', 22 | desc: 23 | 'Копира стойностите на всички изброени свойства на един или повече обекти към друг обект. Връща новия обект като стойност. Въпреки, че чисто технически не е вътрешен метод, по-често когато се използва ES6 се среща Spread Operator ето така: ...', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 'ново свойство или да променя съществуващо', 37 | desc: `Добавя свойство с даденото име, определено с подадените параметри.
38 |
39 | Важно за начинаещи! По-чесно се използват точка или квадратни скоби, когато се създава ново свойство или се променя съществуващо такова. Например: obj.a = 1 или obj[a] = 1. Технически, това не е вграден метод и затова не е включен.`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: 'едно или повече свойства или да променя съществуващи', 53 | desc: `Добавя едно или повече свойства към обекта, определени от параметрите.
54 |
55 | Важно за начинаещи! По-чесно се използват точка или квадратни скоби, когато се създава ново свойство или се променя съществуващо такова. Например: obj.a = 1 или obj[a] = 1. Технически, това не е вграден метод и затова не е включен.`, 56 | example: `Object.defineProperties(obj, {
57 |   d: {
58 |     value: 4,
59 |     writable: true
60 |   },
61 |   e: {
62 |     value: 5,
63 |     writable: true
64 |   }
65 | });
66 |
67 | console.log(obj);`, 68 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 69 | } 70 | ], 71 | infoObj: [ 72 | { 73 | name: 'isExtensible', 74 | shortDesc: 'дали повече свойства могат да бъдат добавени', 75 | desc: 'Определя дали удължаването на обекта е разрешено.', 76 | example: `console.log(Object.isExtensible(obj));
77 | Object.freeze(obj);
78 | console.log(Object.isExtensible(obj));`, 79 | output: `true
80 | false` 81 | }, 82 | { 83 | name: 'is', 84 | shortDesc: 'дали две референции водят към същия обект', 85 | desc: 86 | 'Проверява дали две референции водят към същия обект. Приравнява всички NaN стойности (което се отличава от Abstract Equality Comparison и Strict Equality Comparison). Това е малко странно и MDN документите са малко подвеждащи. По-полезно е да се използва три пъти равно === за проверка на равенство.', 87 | example: `let obj2 = {
88 |   a: 1,
89 |   b: 2,
90 |   c: 3
91 | };
92 |
93 | console.log(Object.is(obj, obj2));
94 | console.log(Object.is(obj, obj));`, 95 | output: `false
96 | true` 97 | }, 98 | { 99 | name: 'isFrozen', 100 | shortDesc: `дали обектът и свойствата му не могат да бъдат променяни`, 101 | desc: 'Проверява дали обектът е замръзен.', 102 | example: `console.log(Object.isFrozen(obj));
103 | Object.freeze(obj);
104 | console.log(Object.isFrozen(obj));`, 105 | output: `false
106 | true` 107 | }, 108 | { 109 | name: 'isSealed', 110 | shortDesc: `дали обектът не може да бъде променян (свойствата могат)`, 111 | desc: 'Определя дали обектът или свойствата му са запечатани.', 112 | example: `Object.seal(obj);
113 |
114 | console.log(Object.isSealed(obj));`, 115 | output: `true` 116 | }, 117 | { 118 | name: 'isPrototypeOf', 119 | shortDesc: `дали обектът е в прототипната верига`, 120 | desc: `Връща булева стойност за това дали обектът е в прототипната верига.`, 121 | example: `function Rect() {}
122 |
123 | var rect = new Rect();
124 |
125 | console.log(Rect.prototype.isPrototypeOf(rect));`, 126 | output: `true`, 127 | useExample: 'newExample' 128 | } 129 | ], 130 | noChange: [ 131 | { 132 | name: 'seal', 133 | shortDesc: `забраня добавяне или премахване на свойства`, 134 | desc: 135 | 'Предпазва свойствата на обект да бъдат изтрити от друг код. Съществуващите свойства могат да бъдат променени.', 136 | example: `Object.seal(obj);
137 | delete obj.c;
138 |
139 | console.log(obj);`, 140 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 141 | }, 142 | { 143 | name: 'freeze', 144 | shortDesc: `забраня добавяне, премахване или промяна на свойства`, 145 | desc: `Замръзява обекта: свойствата не могат да бъдат премахнати или променени.`, 146 | example: `Object.freeze(obj);
147 | obj.a = 10;
148 |
149 | console.log(obj.a);`, 150 | output: `1 //the value didn't update to 10` 151 | }, 152 | { 153 | name: 'preventExtensions', 154 | shortDesc: `забраня добавяне на свойства`, 155 | desc: `Предпазва обекта от удължаване. Свойства могат да бъдат изтрити, но нови не могат да бъдат добавени.`, 156 | example: `Object.preventExtensions(obj);
157 | obj.d = 4;
158 |
159 | console.log(obj.d);`, 160 | output: `undefined` 161 | } 162 | ], 163 | createString: [ 164 | { 165 | name: 'toString', 166 | shortDesc: `обекта представен като низ`, 167 | desc: `Методът toString() връща низ от предоставения обект. Въпреки, че това е достъпния вътрешен метод, обикновено е по-полезно да се използва JSON.stringify()`, 168 | example: `console.log(obj.toString());
169 | console.log(obj.a.toString());`, 170 | output: `"[object Object]"
171 | "1"` 172 | }, 173 | { 174 | name: 'toLocaleString', 175 | shortDesc: `локализиран низ от предоставения обект`, 176 | desc: `Методът toLocaleString() връща низ от предоставения обект. Този метод е предоставен за работа с локализации и може да бъде презаписан от производни обекти. Това означава, че ако имате обект съдържащ разнични данни в зависимост от локацията, например методи за дати, те ще продоставят различен формат.`, 177 | example: `obj.d = new Date();
178 |
179 | console.log(obj.d);
180 | console.log(obj.d.toLocaleString());`, 181 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
182 | 12/29/2017, 8:57:35 PM` 183 | } 184 | ], 185 | infoProp: { 186 | details: [ 187 | { 188 | name: 'getOwnPropertyDescriptor', 189 | shortDesc: `детайли за свойство`, 190 | desc: 'Връща описание на свойство от обекта за свойство с това име.', 191 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
192 |
193 | console.log(o);`, 194 | output: `Object {
195 |   configurable: true,
196 |   enumerable: true,
197 |   value: 1,
198 |   writable: true
199 | }` 200 | }, 201 | { 202 | name: 'getOwnPropertyDescriptors', 203 | shortDesc: `детайли за всички свойства на обекта`, 204 | desc: 205 | 'Връща обект съдържащ всички описания на собствени свойства на обект.', 206 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 207 | output: `Object {
208 |   a: Object {
209 |     configurable: true,
210 |     enumerable: true,
211 |     value: 1,
212 |     writable: true
213 |   },
214 |   b: Object {
215 |     configurable: true,
216 |     enumerable: true,
217 |     value: 2,
218 |     writable: true
219 |   },
220 |   c: Object {
221 |     configurable: true,
222 |     enumerable: true,
223 |     value: 3,
224 |     writable: true
225 |   },
226 | }` 227 | }, 228 | { 229 | name: 'propertyIsEnumerable', 230 | shortDesc: `дали свойство може да бъде обходено с for...in цикъл`, 231 | desc: 232 | 'Връща булева стойност в зависимост дали вътрешния ECMAScript [[Enumerable]] атрибут е зададен. Това може да бъде използвано за проверка дали метод е зададен по подразбиране или е зададен от потребителя, защото зададените по подразбиране свойства обикновено не са Enumerable.', 233 | example: `console.log(obj.propertyIsEnumerable('a'));
234 | console.log(Math.propertyIsEnumerable('random'));`, 235 | output: `true
236 | false` 237 | }, 238 | { 239 | name: 'hasOwnProperty', 240 | shortDesc: `дали свойство съществува като директно свойство на обекта`, 241 | desc: 242 | 'Връща булева стойност в зависимост дали обекта съдържа определеното свойство като директно свойство на този обект, а не наследено чрез прототипната верига.', 243 | example: `console.log(obj.hasOwnProperty('a'));
244 | delete obj.a;
245 | console.log(obj.hasOwnProperty('a'));`, 246 | output: `true
247 | false` 248 | } 249 | ], 250 | list: [ 251 | { 252 | name: 'keys', 253 | shortDesc: `ключове`, 254 | desc: `Връща масив съдържащ имената на всички ключове на обекта. Масива може да бъде обходен в последователността, в която ключовете биха били обходени.`, 255 | example: `console.log(Object.keys(obj));`, 256 | output: `["a", "b", "c"]` 257 | }, 258 | { 259 | name: 'values', 260 | shortDesc: `стойности`, 261 | desc: `Връща масив съдържащ имената на всички стойности на обекта. Масива може да бъде обходен в последователността, в която стойностите биха били обходени.`, 262 | example: `console.log(Object.values(obj));`, 263 | output: `[1, 2, 3]` 264 | }, 265 | { 266 | name: 'entries', 267 | shortDesc: `ключове и стойности`, 268 | desc: `Връща масив от масиви от съдържащи всички двойки ключове и стойности на обекта. Масива може да бъде обходен в последователността, в която ключовете и стойностите биха били обходени.`, 269 | example: `console.log(Object.entries(obj));`, 270 | output: `[["a", 1], ["b", 2], ["c", 3]]` 271 | }, 272 | { 273 | name: 'getOwnPropertyNames', 274 | shortDesc: `ключове дори и да не могат да бъдат обходени`, 275 | desc: `Връща масив съдържащ всички имена на свойства на обект без значение дали могат да бъдат обходени. Прави същото като Object.keys() връщайки ключовете на обекта, но getOwnPropertyNames() също съдържа свойства който не могат да бъдат обходени.`, 276 | example: `Object.defineProperty(obj, 'a', {
277 |   enumerable: false
278 | });
279 |
280 | console.log(Object.keys(obj));
281 | console.log(Object.getOwnPropertyNames(obj));`, 282 | output: `["b", "c"]
283 | ["a", "b", "c"]` 284 | } 285 | ] 286 | }, 287 | prototype: [ 288 | { 289 | name: 'getPrototypeOf', 290 | shortDesc: `получа прототип на обекта`, 291 | desc: `Връща прототипа на подадения обект (тоест, стойността на вътрешното [[Prototype]] свойство).`, 292 | example: `const proto = Object.create(obj);
293 | console.log(Object.getPrototypeOf(proto) === obj);`, 294 | output: `true` 295 | }, 296 | { 297 | name: 'setPrototypeOf', 298 | shortDesc: `задам прототип на обекта`, 299 | desc: `Внимание: този метод е много бавен. Използвайте внимателно или заменете с Object.create(). Задава прототипа (тоест, стойността на вътрешното [[Prototype]] свойство).`, 300 | example: `const dict = Object.setPrototypeOf({}, obj);
301 |
302 | console.log(dict);`, 303 | output: `Object {
304 |   a: 1,
305 |   b: 2,
306 |   c: 3
307 | }` 308 | }, 309 | { 310 | name: 'isPrototypeOf', 311 | shortDesc: `разбера дали обекта е в прототипната верига`, 312 | desc: `Връща булева стойност в зависимост дали обекта е в прототипната верига на подадения в метода обект.`, 313 | example: `function Rect() {}
314 |
315 | var rect = new Rect();
316 |
317 | console.log(Rect.prototype.isPrototypeOf(rect));`, 318 | output: `true` 319 | } 320 | ] 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /src/store/cz.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'vytvořit nový objekt', 8 | desc: `Vytvoří nový objekt s daným objektovým prototypem a vlastnostmi.
9 |
10 | Důležitá poznámka pro začátečníky! Častější je tvorba objektů tak, jako v horním případě, že přiřadíme objekt do proměnné.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'udělat kopii objektu', 22 | desc: 23 | 'Zkopíruje vlastní hodnoty, které lze vyčíst, z jednoho nebo více zdrojových objektů do cílového objektu. Vrácen je cílový objekt.', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 'novou vlastnost nebo upravit existující vlastnost', 37 | desc: `Přidá pojmenovanou vlastnost dle daného deskriptoru.
38 |
39 | Důležitá poznámka pro začátečníky! Častější je použití tečkové notace nebo hranatých závorek pro vytvoření nebo úpravu vlastnosti. Např. obj.a = 1 nebo obj[a] = 1. Protože to není zabudovaná metoda, tak to není ukázáno samostatně.`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: 'jednu nebo více vlastností nebo je upravovat', 53 | desc: `Přidá jednu nebo více vlastností dle daného deskriptoru
54 |
55 | Důležitá poznámka pro začátečníky! Častější je použití tečkové notace nebo hranatých závorek pro vytvoření nebo úpravu vlastnosti. Např. obj.a = 1 nebo obj[a] = 1. Protože to není zabudovaná metoda, tak to není ukázáno samostatně.`, 56 | example: `Object.defineProperties(obj, {
57 |   d: {
58 |     value: 4,
59 |     writable: true
60 |   },
61 |   e: {
62 |     value: 5,
63 |     writable: true
64 |   }
65 | });
66 |
67 | console.log(obj);`, 68 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 69 | } 70 | ], 71 | infoObj: [ 72 | { 73 | name: 'isExtensible', 74 | shortDesc: 'jestli je možné přidat vlastnosti', 75 | desc: 'Zjistí jestli je objekt rozšiřitelný.', 76 | example: `console.log(Object.isExtensible(obj));
77 | Object.freeze(obj);
78 | console.log(Object.isExtensible(obj));`, 79 | output: `true
80 | false` 81 | }, 82 | { 83 | name: 'is', 84 | shortDesc: 'jestli dvě reference odkazují na stejný objekt', 85 | desc: 86 | 'Porovná jestli dvě reference odkazují na stejný objekt. Všechny NaN hodnoty považuje za ekvivalentní, tím se liší od Abstraktního (==) i Přísného (===) Porovnání. Tato funkce je trochu podivná a MDN dokumentace je krapet zavádějící.', 87 | example: `let obj2 = {
88 |   a: 1,
89 |   b: 2,
90 |   c: 3
91 | };
92 |
93 | console.log(Object.is(obj, obj2));
94 | console.log(Object.is(obj, obj));`, 95 | output: `false
96 | true` 97 | }, 98 | { 99 | name: 'isFrozen', 100 | shortDesc: `jestli objekt a jeho vlastnosti jsou neupravitelné`, 101 | desc: 'Zjistí jestli objekt je neměnný (frozen).', 102 | example: `console.log(Object.isFrozen(obj));
103 | Object.freeze(obj);
104 | console.log(Object.isFrozen(obj));`, 105 | output: `false
106 | true` 107 | }, 108 | { 109 | name: 'isSealed', 110 | shortDesc: `jestli objekt je neupravitelný, ale jeho vlastnosti jsou upravitelné`, 111 | desc: 112 | 'Zjistí jestli objekt nebo jeho vlastnosti jsou neupravitelné (sealed).', 113 | example: `Object.seal(obj);
114 |
115 | console.log(Object.isSealed(obj));`, 116 | output: `true` 117 | }, 118 | { 119 | name: 'isPrototypeOf', 120 | shortDesc: `jestli je objekt v prototypovém řetězu.`, 121 | desc: `Vrátí boolean, který říká, jestli je objekt, na kterém je tato metoda volána, v prototypovém řetězu jiného objektu.`, 122 | example: `function Rect() {}
123 |
124 | var rect = new Rect();
125 |
126 | console.log(Rect.prototype.isPrototypeOf(rect));`, 127 | output: `true`, 128 | useExample: 'newExample' 129 | } 130 | ], 131 | noChange: [ 132 | { 133 | name: 'seal', 134 | shortDesc: `zajistit, že vlastnosti nemohou být smazány ani přidány`, 135 | desc: 136 | 'Zabrání jinému kódu smazání vlastností objektu. Existující vlastnosti mohou být upraveny.', 137 | example: `Object.seal(obj);
138 | delete obj.c;
139 |
140 | console.log(obj);`, 141 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 142 | }, 143 | { 144 | name: 'freeze', 145 | shortDesc: `zajistit, že vlastnosti nemohou být smazány,přidány ani upravovány`, 146 | desc: `Zmrazí objekt tak, že jiný kód nemůže změnit nebo upravit jakoukoli vlastnost.`, 147 | example: `Object.freeze(obj);
148 | obj.a = 10;
149 |
150 | console.log(obj.a);`, 151 | output: `1 //the value didn't update to 10` 152 | }, 153 | { 154 | name: 'preventExtensions', 155 | shortDesc: `zajistit, že další vlastnosti nemohou být přidány.`, 156 | desc: `Zabrání všem rozšířením objektu, ale nezabrání jejich smazání.`, 157 | example: `Object.preventExtensions(obj);
158 | obj.d = 4;
159 |
160 | console.log(obj.d);`, 161 | output: `undefined` 162 | } 163 | ], 164 | createString: [ 165 | { 166 | name: 'toString', 167 | shortDesc: `řetězec reprezentující objekt.`, 168 | desc: `toString() metoda vrací řetězec reprezentující objekt.`, 169 | example: `console.log(obj.toString());
170 | console.log(obj.a.toString());`, 171 | output: `"[object Object]"
172 | "1"` 173 | }, 174 | { 175 | name: 'toLocaleString', 176 | shortDesc: `localizovaný řetězec reprezentující objekt.`, 177 | desc: `toLocaleString() metoda vrací řetězec reprezentující objekt. Tato metoda je navržena tak, aby byla přepsána pro místní potřeby. Lidská verze: pokud máte něco, co má jiná data v závislosti na poloze, např. metody pro datum, tak to vrací jiný formát pro datumy podle místa.`, 178 | example: `obj.d = new Date();
179 |
180 | console.log(obj.d);
181 | console.log(obj.d.toLocaleString());`, 182 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
183 | 12/29/2017, 8:57:35 PM` 184 | } 185 | ], 186 | infoProp: { 187 | details: [ 188 | { 189 | name: 'getOwnPropertyDescriptor', 190 | shortDesc: `podrobnosti o vlastnosti`, 191 | desc: 192 | 'Vrátí deskriptor vlastnosti pro pojmenovanou vlastnost objektu.', 193 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
194 |
195 | console.log(o);`, 196 | output: `Object {
197 |   configurable: true,
198 |   enumerable: true,
199 |   value: 1,
200 |   writable: true
201 | }` 202 | }, 203 | { 204 | name: 'getOwnPropertyDescriptors', 205 | shortDesc: `podrobnosti o všech vlastnostech objektu`, 206 | desc: 207 | 'Vrátí objekt obsahující všechny vlastní deskriptory vlastností objektu.', 208 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 209 | output: `Object {
210 |   a: Object {
211 |     configurable: true,
212 |     enumerable: true,
213 |     value: 1,
214 |     writable: true
215 |   },
216 |   b: Object {
217 |     configurable: true,
218 |     enumerable: true,
219 |     value: 2,
220 |     writable: true
221 |   },
222 |   c: Object {
223 |     configurable: true,
224 |     enumerable: true,
225 |     value: 3,
226 |     writable: true
227 |   },
228 | }` 229 | }, 230 | { 231 | name: 'propertyIsEnumerable', 232 | shortDesc: `jestli se vlastnost dostupná pro for...in cyklus`, 233 | desc: 234 | 'Vrací boolean, který říká, jestli je interní ECMAScript [[Enumerable]] atribut nastaven. Tuto funkci lze použít pokud chceme zjistit jestli se jedná o vestavěnou nebo uživatelem definovanou metodu, protože vestavěné metody nemají enumerable nastaveno.', 235 | example: `console.log(obj.propertyIsEnumerable('a'));
236 | console.log(Math.propertyIsEnumerable('random'));`, 237 | output: `true
238 | false` 239 | }, 240 | { 241 | name: 'hasOwnProperty', 242 | shortDesc: `jestli vlastnost existuje jako přímá vlastnost objektu`, 243 | desc: 244 | 'Vrací boolean, který říká, jestli objekt obsahuje danou vlastnost jako přímou vlastnost, nikoli jako zděděnou z prototypového řetězu.', 245 | example: `console.log(obj.hasOwnProperty('a'));
246 | delete obj.a;
247 | console.log(obj.hasOwnProperty('a'));`, 248 | output: `true
249 | false` 250 | } 251 | ], 252 | list: [ 253 | { 254 | name: 'keys', 255 | shortDesc: `klíčů`, 256 | desc: `Vrátí pole klíčů obsahující jména všech klíčů objektu, kterými lze projít v cyklech, řazené tak, jak by byly projity v cyklu.`, 257 | example: `console.log(Object.keys(obj));`, 258 | output: `["a", "b", "c"]` 259 | }, 260 | { 261 | name: 'values', 262 | shortDesc: `hodnot`, 263 | desc: `Vrátí pole hodnot obsahující jména všech hodnot objektu, kterými lze projít v cyklech, řazené tak, jak by byly projity v cyklu.`, 264 | example: `console.log(Object.values(obj));`, 265 | output: `[1, 2, 3]` 266 | }, 267 | { 268 | name: 'entries', 269 | shortDesc: `klíčů a hodnot`, 270 | desc: `Vrací vnořené (nested) pole obsahující jména všech párů klíč-hodnota objektu, kterými lze projít v cyklech, řazené tak, jak by byly projity v cyklu.`, 271 | example: `console.log(Object.entries(obj));`, 272 | output: `[["a", 1], ["b", 2], ["c", 3]]` 273 | }, 274 | { 275 | name: 'getOwnPropertyNames', 276 | shortDesc: `klíčů, i když přes ně nelze procházet v cyclech`, 277 | desc: `Vrací pole obsahující jména všech počitatelných (enumerable) i nepočitatelných vlastností. Dělá to stejné jako Object.keys(), ale getOwnPropertyNames() zahrne i ty vlastnosti, které cykly vynechávají.`, 278 | example: `Object.defineProperty(obj, 'a', {
279 |   enumerable: false
280 | });
281 |
282 | console.log(Object.keys(obj));
283 | console.log(Object.getOwnPropertyNames(obj));`, 284 | output: `["b", "c"]
285 | ["a", "b", "c"]` 286 | } 287 | ] 288 | }, 289 | prototype: [ 290 | { 291 | name: 'getPrototypeOf', 292 | shortDesc: `získat prototyp objektu.`, 293 | desc: `Vrací prototyp daného objektu, hodnotu interní vlastnosti [[Prototype]].`, 294 | example: `const proto = Object.create(obj);
295 | console.log(Object.getPrototypeOf(proto) === obj);`, 296 | output: `true` 297 | }, 298 | { 299 | name: 'setPrototypeOf', 300 | shortDesc: `nastavit prototyp objektu.`, 301 | desc: `Varování: Tato metoda je velmi pomalá. Používej tuto opatrně metodu nebo se jí vyhni přes Object.create(). Nastaví prototyp, hodnotu interní vlastnosti [[Prototype]].`, 302 | example: `const dict = Object.setPrototypeOf({}, obj);
303 |
304 | console.log(dict);`, 305 | output: `Object {
306 |   a: 1,
307 |   b: 2,
308 |   c: 3
309 | }` 310 | }, 311 | { 312 | name: 'isPrototypeOf', 313 | shortDesc: `zjistit jestli je objekt v prototypovém řetězu.`, 314 | desc: `Vrací boolean, který říká, jestli je objekt, na kterém je tato metoda volána, v protypovém řetězu daného objektu.`, 315 | example: `function Rect() {}
316 |
317 | var rect = new Rect();
318 |
319 | console.log(Rect.prototype.isPrototypeOf(rect));`, 320 | output: `true` 321 | } 322 | ] 323 | } 324 | } 325 | -------------------------------------------------------------------------------- /src/store/de.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'ein Objekt erstellen', 8 | desc: `Erstellt ein neues Objekt mit dem vorgegebenen Prototypen und dessen Eigenschaften.
9 |
10 | Wichtiger Hinweis für Anfänger! Es ist üblicher, ein Objekt wie im obigen Beispiel zu erstellen, indem es direkt einer Variable zugewiesen wird.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'eine Kopie eines Objektes erstellen', 22 | desc: 23 | 'Kopiert die Werte aller eigenen aufzählbaren Eigenschaften von einem oder mehreren Quellobjekten in ein Zielobjekt. Zurückgegeben wird das Zielobjekt.', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 'eine neue Eingeschaft oder eine existierende bearbeiten', 37 | desc: `Fügt die Eigenschaft anhand des Beschreibers dem Objekt hinzu.
38 |
39 | Wichtiger Hinweis für Anfänger! Es ist üblicher, die Punkt- oder Klammer-Notation zu verwenden, um neue Eigenschaften zu erstellen oder existierende zu bearbeiten. Beispiel: obj.a = 1 oder obj[a] = 1.`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: 53 | 'eine oder mehrere neue Eigenschaften oder existierende bearbeiten', 54 | desc: `Fügt eine oder mehrere Eigenschaften definiert durch einen gegebenen Beschreiber einem Objekt hinzu.
55 |
56 | Wichtiger Hinweis für Anfänger! Es ist üblicher, die Punkt- oder Klammer-Notation zu verwenden, um neue Eigenschaften zu erstellen oder existierende zu bearbeiten. Beispiel: obj.a = 1 oder obj[a] = 1.`, 57 | example: `Object.defineProperties(obj, {
58 |   d: {
59 |     value: 4,
60 |     writable: true
61 |   },
62 |   e: {
63 |     value: 5,
64 |     writable: true
65 |   }
66 | });
67 |
68 | console.log(obj);`, 69 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 70 | } 71 | ], 72 | infoObj: [ 73 | { 74 | name: 'isExtensible', 75 | shortDesc: 'ob mehrere Eigenschaften hinzugefügt werden können', 76 | desc: 'Findet heraus, ob das Erweitern des Objektes erlaubt ist.', 77 | example: `console.log(Object.isExtensible(obj));
78 | Object.freeze(obj);
79 | console.log(Object.isExtensible(obj));`, 80 | output: `true
81 | false` 82 | }, 83 | { 84 | name: 'is', 85 | shortDesc: 'ob zwei Referenzen auf das gleiche Objekt verweisen', 86 | desc: 87 | 'Vergleicht, ob zwei Referenzen auf das gleiche Objekt verweisen. Setzt alle NaN-Werte gleich (was sich von der losen Gleichheit (Abstract Equality Comparison) und der strikten Gleichheit (Strict Equality Comparison) unterscheidet. Diese Tatsache ist ein wenig seltsam und die MDN-Dokumentation dazu ein bisschen irreführend.', 88 | example: `let obj2 = {
89 |   a: 1,
90 |   b: 2,
91 |   c: 3
92 | };
93 |
94 | console.log(Object.is(obj, obj2));
95 | console.log(Object.is(obj, obj));`, 96 | output: `false
97 | true` 98 | }, 99 | { 100 | name: 'isFrozen', 101 | shortDesc: `ob ein Objekt und dessen Eigenschaften nicht bearbeitet werden können`, 102 | desc: 'Stellt fest, ob ein Objekt "gefroren" ist.', 103 | example: `console.log(Object.isFrozen(obj));
104 | Object.freeze(obj);
105 | console.log(Object.isFrozen(obj));`, 106 | output: `false
107 | true` 108 | }, 109 | { 110 | name: 'isSealed', 111 | shortDesc: `ob ein Objekt nicht bearbeitet werden kann (dessen Eigeschaften jedoch schon)`, 112 | desc: 113 | 'Stellt fest, ob ein Objekt oder dessen Eingeschaften "versiegelt" sind.', 114 | example: `Object.seal(obj);
115 |
116 | console.log(Object.isSealed(obj));`, 117 | output: `true` 118 | }, 119 | { 120 | name: 'isPrototypeOf', 121 | shortDesc: `ob sich das Objekt in der Prototypenkette befindet.`, 122 | desc: `Gibt einen boolschen Wert zurück, der angibt, ob das Objekt, auf dem die Methode aufgerufen wird, sich in der Prototypenkette befindet.`, 123 | example: `function Rect() {}
124 |
125 | var rect = new Rect();
126 |
127 | console.log(Rect.prototype.isPrototypeOf(rect));`, 128 | output: `true`, 129 | useExample: 'newExample' 130 | } 131 | ], 132 | noChange: [ 133 | { 134 | name: 'seal', 135 | shortDesc: `sicherstellen, dass Eigenschaften nicht hinzugefügt oder gelöscht werden`, 136 | desc: 137 | 'Verhindert das Löschen von Objekt-Eigenschaften. Bestehende Eigenschaften können weiterhin bearbeitet werden. ', 138 | example: `Object.seal(obj);
139 | delete obj.c;
140 |
141 | console.log(obj);`, 142 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 143 | }, 144 | { 145 | name: 'freeze', 146 | shortDesc: `sicherstellen, dass Eigenschaften nicht hinzugefügt, gelöscht oder bearbeitet werden`, 147 | desc: `Friert ein Objekt ein: Eigenschaften können danach weder gelöscht noch bearbeitet werden.`, 148 | example: `Object.freeze(obj);
149 | obj.a = 10;
150 |
151 | console.log(obj.a);`, 152 | output: `1 //the value didn't update to 10` 153 | }, 154 | { 155 | name: 'preventExtensions', 156 | shortDesc: `sicherstellen, dass Eigenschaften nicht hinzugefügt werden können.`, 157 | desc: `Verhindert jegliche Erweiterung des Objektes. Bestehende Eigenschaften können jedoch entfernt werden.`, 158 | example: `Object.preventExtensions(obj);
159 | obj.d = 4;
160 |
161 | console.log(obj.d);`, 162 | output: `undefined` 163 | } 164 | ], 165 | createString: [ 166 | { 167 | name: 'toString', 168 | shortDesc: `eine String-Repräsentation des Objektes.`, 169 | desc: `Die toString()-Methode gibt einen String zurück, der das Objekt als Zeichenkette darstellt.`, 170 | example: `console.log(obj.toString());
171 | console.log(obj.a.toString());`, 172 | output: `"[object Object]"
173 | "1"` 174 | }, 175 | { 176 | name: 'toLocaleString', 177 | shortDesc: `eine String-Repräsentation des Objektes in sprachabhängiger Formatierung.`, 178 | desc: `Die toLocaleString()-Methode gibt einen String zurück, der das Objekt als Zeichenkette darstellt. Diese Methode ist dazu gedacht, um von abgeleitetn Objekten zur sprachabhängigen Formattierung überladen zu werden. In anderen Worten: Die Daten sind abhängig vom Ort, wie z.B. bei Datumsmethoden, welche dir ein anderes Format liefern.`, 179 | example: `obj.d = new Date();
180 |
181 | console.log(obj.d);
182 | console.log(obj.d.toLocaleString());`, 183 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
184 | 12/29/2017, 8:57:35 PM` 185 | } 186 | ], 187 | infoProp: { 188 | details: [ 189 | { 190 | name: 'getOwnPropertyDescriptor', 191 | shortDesc: `Details über eine Eigenschaft`, 192 | desc: 'Liefert eine Beschreibung für eine Objekt-Eigenschaft zurück.', 193 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
194 |
195 | console.log(o);`, 196 | output: `Object {
197 |   configurable: true,
198 |   enumerable: true,
199 |   value: 1,
200 |   writable: true
201 | }` 202 | }, 203 | { 204 | name: 'getOwnPropertyDescriptors', 205 | shortDesc: `Details über alle Eingeschaften auf dem Objekt`, 206 | desc: 'Liefert ein Objekt mit allen Eigenschaftsdetails zurück.', 207 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 208 | output: `Object {
209 |   a: Object {
210 |     configurable: true,
211 |     enumerable: true,
212 |     value: 1,
213 |     writable: true
214 |   },
215 |   b: Object {
216 |     configurable: true,
217 |     enumerable: true,
218 |     value: 2,
219 |     writable: true
220 |   },
221 |   c: Object {
222 |     configurable: true,
223 |     enumerable: true,
224 |     value: 3,
225 |     writable: true
226 |   },
227 | }` 228 | }, 229 | { 230 | name: 'propertyIsEnumerable', 231 | shortDesc: `ob eine Eigenschaft mit einer "for...in"-Schleife durchlaufen werden kann`, 232 | desc: 233 | 'Liefert einen boolschen Wert zurück, der angibt, ob das interne ECMAScript [[Enumerable]]-Attribut gesetzt ist. Dies kann zur Bestimmung, ob es sich um eine integrierte oder vom Benutzer definierte Methode handelt, verwendet werden, da integrierte Eigenschaften nicht aufgezählt werden.', 234 | example: `console.log(obj.propertyIsEnumerable('a'));
235 | console.log(Math.propertyIsEnumerable('random'));`, 236 | output: `true
237 | false` 238 | }, 239 | { 240 | name: 'hasOwnProperty', 241 | shortDesc: `ob eine Eigenschaft direkt auf dem Objekt existiert`, 242 | desc: 243 | 'Liefert einen boolschen Wert zurück, der angibt, ob ein Objekt die gegebene Eigenschaft als direkte Eingeschaft auf dem Objekt besitzt und nicht durch Prototypen vererbt wurde.', 244 | example: `console.log(obj.hasOwnProperty('a'));
245 | delete obj.a;
246 | console.log(obj.hasOwnProperty('a'));`, 247 | output: `true
248 | false` 249 | } 250 | ], 251 | list: [ 252 | { 253 | name: 'keys', 254 | shortDesc: `Eigenschaftsnamen`, 255 | desc: `Liefert ein Array mit allen Eigenschaftsnamen, die auf dem Objekt definiert sind.`, 256 | example: `console.log(Object.keys(obj));`, 257 | output: `["a", "b", "c"]` 258 | }, 259 | { 260 | name: 'values', 261 | shortDesc: `Eigenschaftswerten`, 262 | desc: `Liefert ein Array mit allen Eigenschaftswerten vom Objekt.`, 263 | example: `console.log(Object.values(obj));`, 264 | output: `[1, 2, 3]` 265 | }, 266 | { 267 | name: 'entries', 268 | shortDesc: `Eigenschaftsnamen und -Werten`, 269 | desc: `Liefert ein verschachteltes Array mit allen Eigenschaftsnamen und Werten vom Objekt.`, 270 | example: `console.log(Object.entries(obj));`, 271 | output: `[["a", 1], ["b", 2], ["c", 3]]` 272 | }, 273 | { 274 | name: 'getOwnPropertyNames', 275 | shortDesc: `Namen, auch wenn sie nicht durchlaufen werden können`, 276 | desc: `Liefert ein Array mit allen aufzählbaren und nicht aufzählbaren Eigenschaften zurück. Liefert alle Namen wie Object.keys(), jedoch beinhaltet getOwnPropertyNames() zusätzlich noch Eigenschaften, die nicht mit einer Schleife durchlauft werden können.`, 277 | example: `Object.defineProperty(obj, 'a', {
278 |   enumerable: false
279 | });
280 |
281 | console.log(Object.keys(obj));
282 | console.log(Object.getOwnPropertyNames(obj));`, 283 | output: `["b", "c"]
284 | ["a", "b", "c"]` 285 | } 286 | ] 287 | }, 288 | prototype: [ 289 | { 290 | name: 'getPrototypeOf', 291 | shortDesc: `den Prototypen des Objektes erhalten.`, 292 | desc: `Liefert den Prototypen des Objektes zurück (den Wert der internen [[Prototype]]-Eigenschaft)).`, 293 | example: `const proto = Object.create(obj);
294 | console.log(Object.getPrototypeOf(proto) === obj);`, 295 | output: `true` 296 | }, 297 | { 298 | name: 'setPrototypeOf', 299 | shortDesc: `den Prototypen des Objektes setzen.`, 300 | desc: `Achtung: Diese Methode ist ziemlich langsam. Verwende es mit Vorsicht oder setze Object.create() ein. Setzt die interne [[Prototype]]-Eigenschaft).`, 301 | example: `const dict = Object.setPrototypeOf({}, obj);
302 |
303 | console.log(dict);`, 304 | output: `Object {
305 |   a: 1,
306 |   b: 2,
307 |   c: 3
308 | }` 309 | }, 310 | { 311 | name: 'isPrototypeOf', 312 | shortDesc: `herausfinden, ob sich das Objekt in der Protoypenkette befindet.`, 313 | desc: `Liefert einen boolschen Wert zurück, der angibt, ob sich das Objekt, auf dem die Methode aufgerufen wird, sich ind der Prototypenkette befindet`, 314 | example: `function Rect() {}
315 |
316 | var rect = new Rect();
317 |
318 | console.log(Rect.prototype.isPrototypeOf(rect));`, 319 | output: `true` 320 | } 321 | ] 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /src/store/en.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'create a new object', 8 | desc: `Creates a new object with the specified prototype object and properties.
9 |
10 | Important note for beginners! It's more common to create an object the way that it's shown at the top of the example, like this let obj = { a: 1 };`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'make a copy of an object', 22 | desc: `Copies the values of all enumerable own properties from one or more source objects to a target object. It will return the target object. Though not technically a built in object method, it's more common when using ES6 to make use of the Spread Operator, by using ...`, 23 | example: `const copy = Object.assign({}, obj);
24 | console.log(copy);`, 25 | output: `Object {
26 |   a: 1,
27 |   b: 2,
28 |   c: 3
29 | }` 30 | } 31 | ], 32 | createProp: [ 33 | { 34 | name: 'defineProperty', 35 | shortDesc: 'a new property or modify an existing one', 36 | desc: `Adds the named property described by a given descriptor to an object.
37 |
38 | Important note for beginners! It's more common to use dot or square bracket notation to create a new property or modify an existing one. Like this: obj.a = 1 or obj[a] = 1. This isn't technically a built-in method, that's why it's not included.`, 39 | example: `Object.defineProperty(obj, 'd', {
40 |   enumerable: true,
41 |   configurable: true,
42 |   writable: true,
43 |   value: 4
44 | });
45 |
46 | console.log(obj.d);`, 47 | output: `4` 48 | }, 49 | { 50 | name: 'defineProperties', 51 | shortDesc: 'one or more properties or modify existing properties', 52 | desc: `Adds one or more properties described by a given descriptor to an object.
53 |
54 | Important note for beginners! It's more common to use dot or square bracket notation to create a new property or modify an existing one. Like this: obj.a = 1 or obj[a] = 1. This isn't technically a built-in method, that's why it's not included.`, 55 | example: `Object.defineProperties(obj, {
56 |   d: {
57 |     value: 4,
58 |     writable: true
59 |   },
60 |   e: {
61 |     value: 5,
62 |     writable: true
63 |   }
64 | });
65 |
66 | console.log(obj);`, 67 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 68 | } 69 | ], 70 | infoObj: [ 71 | { 72 | name: 'isExtensible', 73 | shortDesc: 'if more properties can be added', 74 | desc: 'Determines if extending of an object is allowed.', 75 | example: `console.log(Object.isExtensible(obj));
76 | Object.freeze(obj);
77 | console.log(Object.isExtensible(obj));`, 78 | output: `true
79 | false` 80 | }, 81 | { 82 | name: 'is', 83 | shortDesc: 'if two references point to the same object', 84 | desc: `Compares if two references point to the same object. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison). This one is a little weird, and the MDN docs are a bit misleading. It's more useful to use triple equals === to check equality`, 85 | example: `let obj2 = {
86 |   a: 1,
87 |   b: 2,
88 |   c: 3
89 | };
90 |
91 | console.log(Object.is(obj, obj2));
92 | console.log(Object.is(obj, obj));`, 93 | output: `false
94 | true` 95 | }, 96 | { 97 | name: 'isFrozen', 98 | shortDesc: `if an object and its properties can't be modified`, 99 | desc: 'Determines if an object is frozen.', 100 | example: `console.log(Object.isFrozen(obj));
101 | Object.freeze(obj);
102 | console.log(Object.isFrozen(obj));`, 103 | output: `false
104 | true` 105 | }, 106 | { 107 | name: 'isSealed', 108 | shortDesc: `if an object can't be modified (its properties can be, though)`, 109 | desc: `Determines if the descriptor of its properties can't be changed and new properties can't be created.`, 110 | example: `Object.seal(obj);
111 |
112 | console.log(Object.isSealed(obj));`, 113 | output: `true` 114 | }, 115 | { 116 | name: 'isPrototypeOf', 117 | shortDesc: `if the object is in the prototype chain.`, 118 | desc: `Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.`, 119 | example: `function Rect() {}
120 |
121 | var rect = new Rect();
122 |
123 | console.log(Rect.prototype.isPrototypeOf(rect));`, 124 | output: `true`, 125 | useExample: 'newExample' 126 | } 127 | ], 128 | noChange: [ 129 | { 130 | name: 'seal', 131 | shortDesc: `make sure properties can't be added or deleted`, 132 | desc: 133 | 'Prevents other code from deleting properties of an object. Existing properties can still be modified.', 134 | example: `Object.seal(obj);
135 | delete obj.c;
136 |
137 | console.log(obj);`, 138 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 139 | }, 140 | { 141 | name: 'freeze', 142 | shortDesc: `make sure properties can't be added, deleted, or modified`, 143 | desc: `Freezes an object: other code can't delete or change any properties.`, 144 | example: `Object.freeze(obj);
145 | obj.a = 10;
146 |
147 | console.log(obj.a);`, 148 | output: `1 //the value didn't update to 10` 149 | }, 150 | { 151 | name: 'preventExtensions', 152 | shortDesc: `make sure properties can't be added.`, 153 | desc: `Prevents any extensions of an object. I can still delete properties but can't add any new ones.`, 154 | example: `Object.preventExtensions(obj);
155 | obj.d = 4;
156 |
157 | console.log(obj.d);`, 158 | output: `undefined` 159 | } 160 | ], 161 | createString: [ 162 | { 163 | name: 'toString', 164 | shortDesc: `string representation of the object.`, 165 | desc: `The toString() method returns a string representing the object. Though this is the built-in method available, it's usually more useful to use JSON.stringify()`, 166 | example: `console.log(obj.toString());
167 | console.log(obj.a.toString());`, 168 | output: `"[object Object]"
169 | "1"` 170 | }, 171 | { 172 | name: 'toLocaleString', 173 | shortDesc: `localized string representation of the object.`, 174 | desc: `The toLocaleString() method returns a string representing the object. This method is meant to be overridden by derived objects for locale-specific purposes. In human terms: this means if you have something that has different data based on location, such as date methods, it will give you a different time format`, 175 | example: `obj.d = new Date();
176 |
177 | console.log(obj.d);
178 | console.log(obj.d.toLocaleString());`, 179 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
180 | 12/29/2017, 8:57:35 PM` 181 | } 182 | ], 183 | infoProp: { 184 | details: [ 185 | { 186 | name: 'getOwnPropertyDescriptor', 187 | shortDesc: `details about a property`, 188 | desc: 189 | 'Returns a property descriptor for a named property on an object.', 190 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
191 |
192 | console.log(o);`, 193 | output: `Object {
194 |   configurable: true,
195 |   enumerable: true,
196 |   value: 1,
197 |   writable: true
198 | }` 199 | }, 200 | { 201 | name: 'getOwnPropertyDescriptors', 202 | shortDesc: `details about all the properties on an object`, 203 | desc: 204 | 'Returns an object containing all own property descriptors for an object.', 205 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 206 | output: `Object {
207 |   a: Object {
208 |     configurable: true,
209 |     enumerable: true,
210 |     value: 1,
211 |     writable: true
212 |   },
213 |   b: Object {
214 |     configurable: true,
215 |     enumerable: true,
216 |     value: 2,
217 |     writable: true
218 |   },
219 |   c: Object {
220 |     configurable: true,
221 |     enumerable: true,
222 |     value: 3,
223 |     writable: true
224 |   },
225 | }` 226 | }, 227 | { 228 | name: 'propertyIsEnumerable', 229 | shortDesc: `if a property can be traversed with a for...in loop`, 230 | desc: 231 | 'Returns a boolean indicating if the internal ECMAScript [[Enumerable]] attribute is set. This can be used to see if something is a built-in or user-defined method because built-in properties tend to not be enumerable', 232 | example: `console.log(obj.propertyIsEnumerable('a'));
233 | console.log(Math.propertyIsEnumerable('random'));`, 234 | output: `true
235 | false` 236 | }, 237 | { 238 | name: 'hasOwnProperty', 239 | shortDesc: `if a property exists as a direct property of the object`, 240 | desc: 241 | 'Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.', 242 | example: `console.log(obj.hasOwnProperty('a'));
243 | delete obj.a;
244 | console.log(obj.hasOwnProperty('a'));`, 245 | output: `true
246 | false` 247 | } 248 | ], 249 | list: [ 250 | { 251 | name: 'keys', 252 | shortDesc: `keys`, 253 | desc: `Returns an array containing the names of all of the object's keys that can be looped through, in the order that they would be looped through.`, 254 | example: `console.log(Object.keys(obj));`, 255 | output: `["a", "b", "c"]` 256 | }, 257 | { 258 | name: 'values', 259 | shortDesc: `values`, 260 | desc: `Returns an array containing the names of all of the object's values that can be looped through, in the order that they would be looped through.`, 261 | example: `console.log(Object.values(obj));`, 262 | output: `[1, 2, 3]` 263 | }, 264 | { 265 | name: 'entries', 266 | shortDesc: `keys and values`, 267 | desc: `Returns a nested array containing the names of all of the object's key/value pairs that can be looped through, in the order that they would be looped through.`, 268 | example: `console.log(Object.entries(obj));`, 269 | output: `[["a", 1], ["b", 2], ["c", 3]]` 270 | }, 271 | { 272 | name: 'getOwnPropertyNames', 273 | shortDesc: `keys, even if you can't loop through them`, 274 | desc: `Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties. Does the same thing as Object.keys(), retrieving the keys in the object, but getOwnPropertyNames() will include properties that can't be looped through.`, 275 | example: `Object.defineProperty(obj, 'a', {
276 |   enumerable: false
277 | });
278 |
279 | console.log(Object.keys(obj));
280 | console.log(Object.getOwnPropertyNames(obj));`, 281 | output: `["b", "c"]
282 | ["a", "b", "c"]` 283 | } 284 | ] 285 | }, 286 | prototype: [ 287 | { 288 | name: 'getPrototypeOf', 289 | shortDesc: `get a prototype of the object.`, 290 | desc: `Returns the prototype of the specified object. (i.e. the value of the internal [[Prototype]] property) of the specified object).`, 291 | example: `const proto = Object.create(obj);
292 | console.log(Object.getPrototypeOf(proto) === obj);`, 293 | output: `true` 294 | }, 295 | { 296 | name: 'setPrototypeOf', 297 | shortDesc: `set a prototype of the object.`, 298 | desc: `Warning: this method is really slow. Use with caution, or replace with Object.create(). Sets the prototype (i.e., the internal [[Prototype]] property).`, 299 | example: `const dict = Object.setPrototypeOf({}, obj);
300 |
301 | console.log(dict);`, 302 | output: `Object {
303 |   a: 1,
304 |   b: 2,
305 |   c: 3
306 | }` 307 | }, 308 | { 309 | name: 'isPrototypeOf', 310 | shortDesc: `find out if the object is in the prototype chain.`, 311 | desc: `Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.`, 312 | example: `function Rect() {}
313 |
314 | var rect = new Rect();
315 |
316 | console.log(Rect.prototype.isPrototypeOf(rect));`, 317 | output: `true` 318 | } 319 | ] 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /src/store/es.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [{ 5 | name: 'create', 6 | shortDesc: 'crear un nuevo objeto', 7 | desc: `Crea un nuevo objeto con el objeto y propiedades del prototipo especificado.
8 |
9 | ¡Nota importante para los principiantes! Es más común crear un objeto de la manera que se muestra en la parte superior del ejemplo, como sigue let obj = { a: 1 }; .`, 10 | example: `const obj2 = Object.create(obj);
11 | console.log(obj2);`, 12 | output: `Object {
13 |   a: 1,
14 |   b: 2,
15 |   c: 3
16 | }` 17 | }, 18 | { 19 | name: 'assign', 20 | shortDesc: 'realizar una copia de un objeto', 21 | desc: 'Copiar los valores de todas la propiedades enumerables de uno o más objetos fuente a un objeto destino. Retorna el objeto destino. Aunque no es técnicamente un método de objeto incorporado, es más común cuando se usa ES6 para hacer uso de Operador de propagación, usando ....', 22 | example: `const copy = Object.assign({}, obj);
23 | console.log(copy);`, 24 | output: `Object {
25 |   a: 1,
26 |   b: 2,
27 |   c: 3
28 | }` 29 | } 30 | ], 31 | createProp: [{ 32 | name: 'defineProperty', 33 | shortDesc: 'una nueva propiedad o modificar una existente', 34 | desc: `Define una nueva propiedad sobre un objeto, o modifica una ya existente, y devuelve el objeto modificado.
35 |
36 | ¡Nota importante para los principiantes! Es más común usar notación de punto o de corchete para crear una nueva propiedad o modificar una existente. Así: obj.a = 1 o obj[a] = 1. Esto no es técnicamente un método incorporado, por eso no está incluido.`, 37 | example: `Object.defineProperty(obj, 'd', {
38 |   enumerable: true,
39 |   configurable: true,
40 |   writable: true,
41 |   value: 4
42 | });
43 |
44 | console.log(obj.d);`, 45 | output: `4` 46 | }, 47 | { 48 | name: 'defineProperties', 49 | shortDesc: 'una o mas propiedades o modificar propiedades existentes', 50 | desc: `Añade una o mas propiedades o modifica propiedades existentes directamente en el objeto, retornando el objeto.
51 |
52 | Nota importante para los principiantes! Es más común utilizar notación de punto o de corchete para crear una nueva propiedad o modificar una existente. Así: obj.a = 1 o obj[a] = 1. Técnicamente no es un método incorporado, por eso no está incluido.`, 53 | example: `Object.defineProperties(obj, {
54 |   d: {
55 |     value: 4,
56 |     writable: true
57 |   },
58 |   e: {
59 |     value: 5,
60 |     writable: true
61 |   }
62 | });
63 |
64 | console.log(obj);`, 65 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 66 | } 67 | ], 68 | infoObj: [{ 69 | name: 'isExtensible', 70 | shortDesc: 'si mas propiedades pueden ser agregadas', 71 | desc: 'Determina si un objeto puede tener propiedades nuevas agregadas.', 72 | example: `console.log(Object.isExtensible(obj));
73 | Object.freeze(obj);
74 | console.log(Object.isExtensible(obj));`, 75 | output: `true
76 | false` 77 | }, 78 | { 79 | name: 'is', 80 | shortDesc: 'si dos referencias apuntan al mismo objeto', 81 | desc: 'Compara si dos referencias apuntan al mismo objeto. Iguala todos los valores NaN (que difiere tanto de la Comparación de igualdad abstracta como de la Comparación de igualdad estricta). Éste es un poco raro, y los documentos de los MDN son un poco engañosos. Esta opción es más útil a utilizar triple igualdad ==== para las comprobaciones.', 82 | example: `let obj2 = {
83 |   a: 1,
84 |   b: 2,
85 |   c: 3
86 | };
87 |
88 | console.log(Object.is(obj, obj2));
89 | console.log(Object.is(obj, obj));`, 90 | output: `false
91 | true` 92 | }, 93 | { 94 | name: 'isFrozen', 95 | shortDesc: `si un objeto y sus propiedades no pueden ser modificadas`, 96 | desc: 'Determina si un objeto esta congelado', 97 | example: `console.log(Object.isFrozen(obj));
98 | Object.freeze(obj);
99 | console.log(Object.isFrozen(obj));`, 100 | output: `false
101 | true` 102 | }, 103 | { 104 | name: 'isSealed', 105 | shortDesc: `si un objeto no puede ser modificado (aunque sus propiedades pueden serlo)`, 106 | desc: 'Determina si el descriptor de sus propiedades no se puede cambiar y no se pueden crear nuevas propiedades.', 107 | example: `Object.seal(obj);
108 |
109 | console.log(Object.isSealed(obj));`, 110 | output: `true` 111 | }, 112 | { 113 | name: 'isPrototypeOf', 114 | shortDesc: `comprobar si un objeto se encuentra en la cadena de prototipado de otro.`, 115 | desc: `Devuelve un booleano indicando si el objeto al que se llama este método está en la cadena de prototipos del objeto especificado.`, 116 | example: `function Rect() {}
117 |
118 | var rect = new Rect();
119 |
120 | console.log(Rect.prototype.isPrototypeOf(rect));`, 121 | output: `true`, 122 | useExample: 'newExample' 123 | } 124 | ], 125 | noChange: [{ 126 | name: 'seal', 127 | shortDesc: `asegurarse de que las propiedades no se pueden añadir o eliminar`, 128 | desc: 'Impide que otro código borre las propiedades de un objeto. Las propiedades existentes todavía pueden ser modificadas.', 129 | example: `Object.seal(obj);
130 | delete obj.c;
131 |
132 | console.log(obj);`, 133 | output: `{a: 1, b: 2, c: 3} // obj.c no se elimina` 134 | }, 135 | { 136 | name: 'freeze', 137 | shortDesc: `asegurarse de que las propiedades no se pueden añadir, eliminar o modificar`, 138 | desc: `Congela un objeto: otro código no puede borrar o cambiar ninguna propiedad.`, 139 | example: `Object.freeze(obj);
140 | obj.a = 10;
141 |
142 | console.log(obj.a);`, 143 | output: `1 //el valor no se actualiza a 10` 144 | }, 145 | { 146 | name: 'preventExtensions', 147 | shortDesc: `asegurarse de que no se pueden añadir propiedades.`, 148 | desc: `Previene cualquier extensión de un objeto. Todavía se pueden eliminar propiedades pero no se puede añadir ninguna nueva.`, 149 | example: `Object.preventExtensions(obj);
150 | obj.d = 4;
151 |
152 | console.log(obj.d);`, 153 | output: `undefined` 154 | } 155 | ], 156 | createString: [{ 157 | name: 'toString', 158 | shortDesc: `cadena de caracteres representando al objeto`, 159 | desc: `El método toString() devuelve una cadena de caracteres que representa el objeto. Aunque este es el método incorporado disponible, normalmente es más útil usar JSON.stringify().`, 160 | example: `console.log(obj.toString());
161 | console.log(obj.a.toString());`, 162 | output: `"[object Object]"
163 | "1"` 164 | }, 165 | { 166 | name: 'toLocaleString', 167 | shortDesc: `devolver la representación del objeto como una cadena utilizando la configuración regional.`, 168 | desc: `El método toLocaleString() devuelve una cadena que representa el objeto. Este método debe ser sustituido por objetos derivados para fines específicos de la configuración regional. En términos humanos: esto significa que si tienes algo que tiene datos diferentes basados en la ubicación, como métodos de fecha, te dará un formato de hora diferente.`, 169 | example: `obj.d = new Date();
170 |
171 | console.log(obj.d);
172 | console.log(obj.d.toLocaleString());`, 173 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
174 | 12/29/2017, 8:57:35 PM` 175 | } 176 | ], 177 | infoProp: { 178 | details: [{ 179 | name: 'getOwnPropertyDescriptor', 180 | shortDesc: `detalles sobre una propiedad`, 181 | desc: 'Devuelve un descriptor para una propiedad en un objeto.', 182 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
183 |
184 | console.log(o);`, 185 | output: `Object {
186 |   configurable: true,
187 |   enumerable: true,
188 |   value: 1,
189 |   writable: true
190 | }` 191 | }, 192 | { 193 | name: 'getOwnPropertyDescriptors', 194 | shortDesc: `detalles sobre todas las propiedades de un objeto`, 195 | desc: 'Devuelve un objeto que contiene todos las descripciones de propiedad propias de un objeto.', 196 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 197 | output: `Object {
198 |   a: Object {
199 |     configurable: true,
200 |     enumerable: true,
201 |     value: 1,
202 |     writable: true
203 |   },
204 |   b: Object {
205 |     configurable: true,
206 |     enumerable: true,
207 |     value: 2,
208 |     writable: true
209 |   },
210 |   c: Object {
211 |     configurable: true,
212 |     enumerable: true,
213 |     value: 3,
214 |     writable: true
215 |   },
216 | }` 217 | }, 218 | { 219 | name: 'propertyIsEnumerable', 220 | shortDesc: `si una propiedad puede ser recorrida con un bucle for... in`, 221 | desc: 'Devuelve un booleano que indica si el atributo interno ECMAScript [[Enumerable]] está configurado. Esto se puede utilizar para ver si algo es un método incorporado o definido por el usuario porque las propiedades incorporadas tienden a no ser enumerables.', 222 | example: `console.log(obj.propertyIsEnumerable('a'));
223 | console.log(Math.propertyIsEnumerable('random'));`, 224 | output: `true
225 | false` 226 | }, 227 | { 228 | name: 'hasOwnProperty', 229 | shortDesc: `si existe una propiedad como propiedad directa del objeto`, 230 | desc: 'Devuelve un booleano indicando si un objeto contiene la propiedad especificada como una propiedad directa de ese objeto y no heredada a través de la cadena del prototipo.', 231 | example: `console.log(obj.hasOwnProperty('a'));
232 | delete obj.a;
233 | console.log(obj.hasOwnProperty('a'));`, 234 | output: `true
235 | false` 236 | } 237 | ], 238 | list: [{ 239 | name: 'keys', 240 | shortDesc: `claves`, 241 | desc: `Devuelve un array que contiene los nombres de todas las claves del objeto por las que se puede hacer un bucle, en el orden en que se harían.`, 242 | example: `console.log(Object.keys(obj));`, 243 | output: `["a", "b", "c"]` 244 | }, 245 | { 246 | name: 'values', 247 | shortDesc: `valores`, 248 | desc: `Devuelve un array que contiene los nombres de todos los valores del objeto por los que se puede hacer un bucle, en el orden en que se harían.`, 249 | example: `console.log(Object.values(obj));`, 250 | output: `[1, 2, 3]` 251 | }, 252 | { 253 | name: 'entries', 254 | shortDesc: `claves y valores`, 255 | desc: `Devuelve un array anidado que contiene los nombres de todos los pares clave/valor del objeto a través de los que se puede hacer un bucle, en el orden en que se harían.`, 256 | example: `console.log(Object.entries(obj));`, 257 | output: `[["a", 1], ["b", 2], ["c", 3]]` 258 | }, 259 | { 260 | name: 'getOwnPropertyNames', 261 | shortDesc: `claves, incluso si no puedes pasar a través de ellas`, 262 | desc: `Devuelve un array que contiene los nombres de todas las propiedades enumerables y no numerables del objeto en cuestión. Hace lo mismo que Object.keys(), recuperando las claves del objeto, pero getOwnPropertyNames() incluye propiedades que no pueden ser enlazadas.`, 263 | example: `Object.defineProperty(obj, 'a', {
264 |   enumerable: false
265 | });
266 |
267 | console.log(Object.keys(obj));
268 | console.log(Object.getOwnPropertyNames(obj));`, 269 | output: `["b", "c"]
270 | ["a", "b", "c"]` 271 | } 272 | ] 273 | }, 274 | prototype: [{ 275 | name: 'getPrototypeOf', 276 | shortDesc: `conseguir un prototipo del objeto.`, 277 | desc: `Devuelve el prototipo del objeto especificado. (es decir, el valor de la propiedad interna [[Prototype]]) del objeto especificado).`, 278 | example: `const proto = Object.create(obj);
279 | console.log(Object.getPrototypeOf(proto) === obj);`, 280 | output: `true` 281 | }, 282 | { 283 | name: 'setPrototypeOf', 284 | shortDesc: `asigna un prototipo al objeto.`, 285 | desc: `Advertencia: este método es realmente lento. Utilizar con precaución, o sustituir por Object.create (). Establece el prototipo (es decir, la propiedad interna [[Prototype]]).`, 286 | example: `const dict = Object.setPrototypeOf({}, obj);
287 |
288 | console.log(dict);`, 289 | output: `Object {
290 |   a: 1,
291 |   b: 2,
292 |   c: 3
293 | }` 294 | }, 295 | { 296 | name: 'isPrototypeOf', 297 | shortDesc: `averiguar si el objeto está en la cadena del prototipo.`, 298 | desc: `Devuelve un booleano indicando si el objeto al que se llama este método está en la cadena de prototipos del objeto especificado.`, 299 | example: `function Rect() {}
300 |
301 | var rect = new Rect();
302 |
303 | console.log(Rect.prototype.isPrototypeOf(rect));`, 304 | output: `true` 305 | } 306 | ] 307 | } 308 | } -------------------------------------------------------------------------------- /src/store/fr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'créer un nouvel objet', 8 | desc: `Crée un nouvel objet avec un prototype et des propriétés spécifiques.
9 |
10 | Remarque importante pour les débutants ! Il est plus courant de créer un objet de la façon donnée en exemple en haut, en l'assignant à une variable.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: "faire une copie d'un objet", 22 | desc: `Copie les valeurs de toutes les propriétés énumérables d'un ou plusieurs objet(s) vers un objet cible, qui sera retourné.`, 23 | example: `const copie = Object.assign({}, obj);
24 | console.log(copie);`, 25 | output: `Object {
26 |   a: 1,
27 |   b: 2,
28 |   c: 3
29 | }` 30 | } 31 | ], 32 | createProp: [ 33 | { 34 | name: 'defineProperty', 35 | shortDesc: 'une nouvelle propriété ou modifier une propriété existante', 36 | desc: `Ajoute une propriété à un objet ou modifie une propiété existante.
37 |
38 | Remarque importante pour les débutants ! Il est plus courant d'utiliser les notations avec point ou crochets pour créer une nouvelle propriété ou modifier une propriété existante, comme ceci : obj.a = 1 ou obj[a] = 1.`, 39 | example: `Object.defineProperty(obj, 'd', {
40 |   enumerable: true,
41 |   configurable: true,
42 |   writable: true,
43 |   value: 4
44 | });
45 |
46 | console.log(obj.d);`, 47 | output: `4` 48 | }, 49 | { 50 | name: 'defineProperties', 51 | shortDesc: 52 | 'une ou plusieurs propriétés ou modifier des propriétés existantes', 53 | desc: `Ajoute une ou plusieurs propriétés à un objet ou modifie des propriétés existantes.
54 |
55 | Remarque importante pour les débutants ! Il est plus courant d'utiliser les notations avec point ou crochets pour créer une nouvelle propriété ou modifier une propriété existante, comme ceci : obj.a = 1 ou obj[a] = 1.`, 56 | example: `Object.defineProperties(obj, {
57 |   d: {
58 |     value: 4,
59 |     writable: true
60 |   },
61 |   e: {
62 |     value: 5,
63 |     writable: true
64 |   }
65 | });
66 |
67 | console.log(obj);`, 68 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 69 | } 70 | ], 71 | infoObj: [ 72 | { 73 | name: 'isExtensible', 74 | shortDesc: 'si plus de propriétés peuvent être ajoutées', 75 | desc: `Détermine si un objet est extensible (c'est-à-dire qu'on peut lui ajouter de nouvelles propriétés).`, 76 | example: `console.log(Object.isExtensible(obj));
77 | Object.freeze(obj);
78 | console.log(Object.isExtensible(obj));`, 79 | output: `true
80 | false` 81 | }, 82 | { 83 | name: 'is', 84 | shortDesc: 'si deux références pointent vers le même objet', 85 | desc: `Vérifie que deux références pointent vers le même objet. Diffère des comparaisons abstraite (Abstract Equality Comparison) et stricte (Strict Equality Comparison). Celle-ci est un peu bizarre, et la documentation MDN est trompeuse.`, 86 | example: `let obj2 = {
87 |   a: 1,
88 |   b: 2,
89 |   c: 3
90 | };
91 |
92 | console.log(Object.is(obj, obj2));
93 | console.log(Object.is(obj, obj));`, 94 | output: `false
95 | true` 96 | }, 97 | { 98 | name: 'isFrozen', 99 | shortDesc: `si un objet et ses propriétés ne peuvent pas être modifiés`, 100 | desc: `Détermine si un objet est gelé, c'est-à-dire si qu'on empêche d'ajouter de nouvelles propriétés, de supprimer ou d'éditer des propriétés existantes.`, 101 | example: `console.log(Object.isFrozen(obj));
102 | Object.freeze(obj);
103 | console.log(Object.isFrozen(obj));`, 104 | output: `false
105 | true` 106 | }, 107 | { 108 | name: 'isSealed', 109 | shortDesc: `si un objet ne peut pas être modifié (mais ses propriétés oui)`, 110 | desc: `Détermine si un objet ou ses propriétés sont scellés : on ne peut ni ajouter ni retirer de propriétés, mais on peut modifier des propriétés existantes.`, 111 | example: `Object.seal(obj);
112 |
113 | console.log(Object.isSealed(obj));`, 114 | output: `true` 115 | }, 116 | { 117 | name: 'isPrototypeOf', 118 | shortDesc: `si l'objet est dans la chaîne de prototype.`, 119 | desc: `Retourne un booléen indiquant si un objet fait partie de la chaîne de prototypes d'un autre objet.`, 120 | example: `function Rect() {}
121 |
122 | var rect = new Rect();
123 |
124 | console.log(Rect.prototype.isPrototypeOf(rect));`, 125 | output: `true`, 126 | useExample: 'newExample' 127 | } 128 | ], 129 | noChange: [ 130 | { 131 | name: 'seal', 132 | shortDesc: `empêcher l'ajout ou la suppression de propriétés`, 133 | desc: `Scelle un objet, ce qui empêche l'ajout ou la suppression de propriétés. Les propriétés existantes peuvent toujours être modifiées.`, 134 | example: `Object.seal(obj);
135 | delete obj.c;
136 |
137 | console.log(obj);`, 138 | output: `{a: 1, b: 2, c: 3} // obj.c n'est pas supprimé` 139 | }, 140 | { 141 | name: 'freeze', 142 | shortDesc: `empêcher l'ajout, la suppression ou la modification de propriétés`, 143 | desc: `Gèle un objet, ce qui empêche l'ajout, la suppression ou la modification de propriétés.`, 144 | example: `Object.freeze(obj);
145 | obj.a = 10;
146 |
147 | console.log(obj.a);`, 148 | output: `1 //the value didn't update to 10` 149 | }, 150 | { 151 | name: 'preventExtensions', 152 | shortDesc: `empêcher l'ajout de propriétés`, 153 | desc: `Empêche l'extention d'un objet. Les propriétés peuvent être supprimées ou modifiées mais on ne peut pas en ajouter de nouvelles.`, 154 | example: `Object.preventExtensions(obj);
155 | obj.d = 4;
156 |
157 | console.log(obj.d);`, 158 | output: `undefined` 159 | } 160 | ], 161 | createString: [ 162 | { 163 | name: 'toString', 164 | shortDesc: `la représentation en chaîne de caractères d'un objet`, 165 | desc: `La méthode toString() retourne une chaîne de caractère représentant l'objet.`, 166 | example: `console.log(obj.toString());
167 | console.log(obj.a.toString());`, 168 | output: `"[object Object]"
169 | "1"` 170 | }, 171 | { 172 | name: 'toLocaleString', 173 | shortDesc: `la représentation en chaîne de caractères localisée d'un objet`, 174 | desc: `La méthode toLocaleString() retourne une représentation en chaîne de caractères localisée d'un objet. Cette méthode utilise des objets dérivés permettant de personnaliser le comportement de la fonction, notamment en fonction de la locale.`, 175 | example: `obj.d = new Date();
176 |
177 | console.log(obj.d);
178 | console.log(obj.d.toLocaleString());`, 179 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
180 | 12/29/2017, 8:57:35 PM` 181 | } 182 | ], 183 | infoProp: { 184 | details: [ 185 | { 186 | name: 'getOwnPropertyDescriptor', 187 | shortDesc: `des détails sur une propriété`, 188 | desc: `Renvoie un descripteur de la propriété propre d'un objet (c'est-à-dire une propriété directement présente et pas héritée via la chaîne de prototypes).`, 189 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
190 |
191 | console.log(o);`, 192 | output: `Object {
193 |   configurable: true,
194 |   enumerable: true,
195 |   value: 1,
196 |   writable: true
197 | }` 198 | }, 199 | { 200 | name: 'getOwnPropertyDescriptors', 201 | shortDesc: `des détails sur toutes les propritétés d'un objet`, 202 | desc: `Retourne un objet contenant les descripteurs de toutes les propriétés d'un objet.`, 203 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 204 | output: `Object {
205 |   a: Object {
206 |     configurable: true,
207 |     enumerable: true,
208 |     value: 1,
209 |     writable: true
210 |   },
211 |   b: Object {
212 |     configurable: true,
213 |     enumerable: true,
214 |     value: 2,
215 |     writable: true
216 |   },
217 |   c: Object {
218 |     configurable: true,
219 |     enumerable: true,
220 |     value: 3,
221 |     writable: true
222 |   },
223 | }` 224 | }, 225 | { 226 | name: 'propertyIsEnumerable', 227 | shortDesc: `si une propriété peut être parcourue par une boucle for...in`, 228 | desc: `Retourne un booléen indiquant si l'attribut interne ECMAScript [[Enumerable]] est défini. Cela peut être utilisé pour savoir si une méthode est native ou non, car les propriétés natives ne sont générallement pas énumérables.`, 229 | example: `console.log(obj.propertyIsEnumerable('a'));
230 | console.log(Math.propertyIsEnumerable('random'));`, 231 | output: `true
232 | false` 233 | }, 234 | { 235 | name: 'hasOwnProperty', 236 | shortDesc: `si une propriété existe comme propriété directe d'un objet`, 237 | desc: `Retourne une booléen indiquant si un objet contient une propriété directe et non pas héritée d'une chaîne de prototypes.`, 238 | example: `console.log(obj.hasOwnProperty('a'));
239 | delete obj.a;
240 | console.log(obj.hasOwnProperty('a'));`, 241 | output: `true
242 | false` 243 | } 244 | ], 245 | list: [ 246 | { 247 | name: 'keys', 248 | shortDesc: `propriétés`, 249 | desc: `Retourne un tableau contenant les noms de toutes les propriétés d'un objet qui peuvent être parcourues.`, 250 | example: `console.log(Object.keys(obj));`, 251 | output: `["a", "b", "c"]` 252 | }, 253 | { 254 | name: 'values', 255 | shortDesc: `valeurs`, 256 | desc: `Retourne un tableau contenant les noms de toutes les valeurs d'un objet qui peuvent être parcourues.`, 257 | example: `console.log(Object.values(obj));`, 258 | output: `[1, 2, 3]` 259 | }, 260 | { 261 | name: 'entries', 262 | shortDesc: `propriétés et valeurs`, 263 | desc: `Retourne un tableau contenant les noms de toutes les paires propriété/valeur d'un objet qui peuvent être parcourues.`, 264 | example: `console.log(Object.entries(obj));`, 265 | output: `[["a", 1], ["b", 2], ["c", 3]]` 266 | }, 267 | { 268 | name: 'getOwnPropertyNames', 269 | shortDesc: `propriétés, même non-énumérables`, 270 | desc: `Retourne un tableau contenant les noms de toutes les propriétés d'un objet, qu'elles soient énumérables ou non. Fait la même chose que Object.keys() (retourne les propriétés d'un objet), mais getOwnPropertyNames() inclut les propriétés non-énumérables.`, 271 | example: `Object.defineProperty(obj, 'a', {
272 |   enumerable: false
273 | });
274 |
275 | console.log(Object.keys(obj));
276 | console.log(Object.getOwnPropertyNames(obj));`, 277 | output: `["b", "c"]
278 | ["a", "b", "c"]` 279 | } 280 | ] 281 | }, 282 | prototype: [ 283 | { 284 | name: 'getPrototypeOf', 285 | shortDesc: `obtenir un prototype de cet objet.`, 286 | desc: `Retourne un protoype de l'objet spécifié, c'est-à-dire la valeur de la propriété interne [[Prototype]].`, 287 | example: `const proto = Object.create(obj);
288 | console.log(Object.getPrototypeOf(proto) === obj);`, 289 | output: `true` 290 | }, 291 | { 292 | name: 'setPrototypeOf', 293 | shortDesc: `définir un protoype de cet objet.`, 294 | desc: `Attention : cette méthode est très lente. Utilisez avec précaution, ou remplacez par Object.create(). Définit le prototype, c'est-à-dire la propriété interne [[Prototype]].`, 295 | example: `const dict = Object.setPrototypeOf({}, obj);
296 |
297 | console.log(dict);`, 298 | output: `Object {
299 |   a: 1,
300 |   b: 2,
301 |   c: 3
302 | }` 303 | }, 304 | { 305 | name: 'isPrototypeOf', 306 | shortDesc: `savoir si cet objet est dans la chaîne de prototypes.`, 307 | desc: `Retourne un booléen indiquant si un objet fait partie de la chaîne de prototypes de l'objet spécifié.`, 308 | example: `function Rect() {}
309 |
310 | var rect = new Rect();
311 |
312 | console.log(Rect.prototype.isPrototypeOf(rect));`, 313 | output: `true` 314 | } 315 | ] 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /src/store/id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'membuat sebuah objek baru', 8 | desc: `Membuat sebuah objek baru dengan objek prototipe dan properti yang ditentukan.
9 |
10 | Catatan penting untuk para pemula! Cara yang lebih umum untuk membuat objek adalah dengan cara yang ditunjukkan pada bagian atas dari contoh, seperti ini let obj = { a: 1 };.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'membuat salinan dari sebuah objek', 22 | desc: 23 | 'Menyalin seluruh nilai dari seluruh properti yang enumerable dari satu atau lebih objek sumber ke sebuah objek target. Metode ini akan mengembalikan objek target. Meskipun metode ini bukanlah metode objek yang built-in, biasanya pada ES6 lebih umum untuk menggunakan Spread Operator, dengan ...', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 37 | 'sebuah properti baru atau memodifikasi properti yang sudah ada', 38 | desc: `Menambahkan properti yang diberikan oleh deskriptor ke sebuah objek.
39 |
40 | Catatan penting untuk para pemula! Cara yang lebih umum adalah dengan menggunakan notasi dot atau kurung siku untuk membuat sebuah properti baru atau memodifikasi yang sudah ada. Seperti ini: obj.a = 1 or obj[a] = 1. Secara teknis, ini bukanlah sebuah metode yang built-in, sehingga tidak diikutsertakan.`, 41 | example: `Object.defineProperty(obj, 'd', {
42 |   enumerable: true,
43 |   configurable: true,
44 |   writable: true,
45 |   value: 4
46 | });
47 |
48 | console.log(obj.d);`, 49 | output: `4` 50 | }, 51 | { 52 | name: 'defineProperties', 53 | shortDesc: 54 | 'satu atau lebih properti atau memodifikasi lebih dari satu properti yang sudah ada', 55 | desc: `Menambahkan satu atau lebih properti yang dijelaskan oleh deskriptor yang diberikan ke sebuah objek.
56 |
57 | Catatan penting untuk para pemula! Cara yang lebih umum adalah dengan menggunakan notasi dot atau kurung siku untuk membuat sebuah properti baru atau memodifikasi yang sudah ada. Seperti ini: obj.a = 1 or obj[a] = 1. Secara teknis, ini bukanlah sebuah metode yang built-in, sehingga tidak diikutsertakan.`, 58 | example: `Object.defineProperties(obj, {
59 |   d: {
60 |     value: 4,
61 |     writable: true
62 |   },
63 |   e: {
64 |     value: 5,
65 |     writable: true
66 |   }
67 | });
68 |
69 | console.log(obj);`, 70 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 71 | } 72 | ], 73 | infoObj: [ 74 | { 75 | name: 'isExtensible', 76 | shortDesc: 'apakah saya dapat menambahkan lebih banyak properti', 77 | desc: 78 | 'Menentukan apakah melakukan ekstensi terhadap suatu objek diperbolehkan.', 79 | example: `console.log(Object.isExtensible(obj));
80 | Object.freeze(obj);
81 | console.log(Object.isExtensible(obj));`, 82 | output: `true
83 | false` 84 | }, 85 | { 86 | name: 'is', 87 | shortDesc: 'apakah dua titik referensi menunjuk ke objek yang sama', 88 | desc: 89 | `Membandingkan apakah dua titik referensi menunjuk ke objek yang sama. Seluruh nilai NaN akan dianggap sama (di mana hal ini berbeda dari Abstract Equality Comparison dan Strict Equality Comparison). Metode ini agak sedikit aneh, dan dokumentasi MDN yang terkait agak sedikit menyesatkan. Sebaiknya, gunakanlah triple equals === untuk mengecek kesetaraan.`, 90 | example: `let obj2 = {
91 |   a: 1,
92 |   b: 2,
93 |   c: 3
94 | };
95 |
96 | console.log(Object.is(obj, obj2));
97 | console.log(Object.is(obj, obj));`, 98 | output: `false
99 | true` 100 | }, 101 | { 102 | name: 'isFrozen', 103 | shortDesc: `apakah sebuah objek dan properti-propertinya tidak dapat dimodifikasi`, 104 | desc: 105 | 'Menentukan apakah sebuah objek merupakan objek yang beku (tidak dapat dimodifikasi).', 106 | example: `console.log(Object.isFrozen(obj));
107 | Object.freeze(obj);
108 | console.log(Object.isFrozen(obj));`, 109 | output: `false
110 | true` 111 | }, 112 | { 113 | name: 'isSealed', 114 | shortDesc: `apakah sebuah objek tidak dapat dimodifikasi (meskipun properti-properti terkait bisa dimodifikasi)`, 115 | desc: 116 | 'Menentukan apakah sebuah objek dan properti-propertinya disegel (sealed).', 117 | example: `Object.seal(obj);
118 |
119 | console.log(Object.isSealed(obj));`, 120 | output: `true` 121 | }, 122 | { 123 | name: 'isPrototypeOf', 124 | shortDesc: `apakah objek tersebut merupakan bagian dari sebuah rantai prototipe`, 125 | desc: `Mengembalikan sebuah boolean yang mengindikasikan apakah objek di mana metode ini dipanggil merupakan bagian dari rantai prototipe (prototype chain) objek yang ditentukan.`, 126 | example: `function Rect() {}
127 |
128 | var rect = new Rect();
129 |
130 | console.log(Rect.prototype.isPrototypeOf(rect));`, 131 | output: `true`, 132 | useExample: 'newExample' 133 | } 134 | ], 135 | noChange: [ 136 | { 137 | name: 'seal', 138 | shortDesc: `memastikan bahwa properti-properti tidak dapat ditambah atau dihapus`, 139 | desc: 140 | 'Menghindari kode lain untuk menghapus properti-properti dari sebuah objek. Properti yang sudah ada sekarang masih dapat dimodifikasi.', 141 | example: `Object.seal(obj);
142 | delete obj.c;
143 |
144 | console.log(obj);`, 145 | output: `{a: 1, b: 2, c: 3} // obj.c tidak dapat dihapus` 146 | }, 147 | { 148 | name: 'freeze', 149 | shortDesc: `memastikan bahwa properti-properti tidak dapat ditambah, dihapus, atau dimodifikasi`, 150 | desc: `Membekukan sebuah objek: kode lain tidak dapat menghapus atau mengubah properti apapun.`, 151 | example: `Object.freeze(obj);
152 | obj.a = 10;
153 |
154 | console.log(obj.a);`, 155 | output: `1 //nilai tidak diubah menjadi 10` 156 | }, 157 | { 158 | name: 'preventExtensions', 159 | shortDesc: `memastikan bahwa properti-properti tidak dapat ditambah`, 160 | desc: `Menghindari ekstensi dari sebuah objek. Properti-properti tetap dapat dihapus, namun tidak bisa ditambah.`, 161 | example: `Object.preventExtensions(obj);
162 | obj.d = 4;
163 |
164 | console.log(obj.d);`, 165 | output: `undefined` 166 | } 167 | ], 168 | createString: [ 169 | { 170 | name: 'toString', 171 | shortDesc: `representasi string dari sebuah objek`, 172 | desc: `Metode toString() mengembalikan sebuah string yang merepresentasikan objek tersebut. Meskipun metode ini adalah metode built-in yang tersedia, biasanya akan lebih berguna apabila Anda menggunakan JSON.stringify()`, 173 | example: `console.log(obj.toString());
174 | console.log(obj.a.toString());`, 175 | output: `"[object Object]"
176 | "1"` 177 | }, 178 | { 179 | name: 'toLocaleString', 180 | shortDesc: `representasi string yang telah dilokalisasi dari sebuah objek`, 181 | desc: `Metode toLocaleString() representasi string yang telah dilokalisasi dari sebuah objek. Metode ini dimaksudkan untuk di-override oleh objek turunan untuk tujuan yang spesifik pada lokal. Dalam bahasa manusia: ini berarti bahwa apabila Anda mempunyai sesuatu yang memiliki data berbeda berdasarkan lokasi, seperti metode tanggal, maka metode ini akan memberikan Anda format waktu yang berbeda`, 182 | example: `obj.d = new Date();
183 |
184 | console.log(obj.d);
185 | console.log(obj.d.toLocaleString());`, 186 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
187 | 12/29/2017, 8:57:35 PM` 188 | } 189 | ], 190 | infoProp: { 191 | details: [ 192 | { 193 | name: 'getOwnPropertyDescriptor', 194 | shortDesc: `detil-detil terkait sebuah properti`, 195 | desc: 196 | 'Mengembalikan sebuah deskriptor properti untuk sebuah properti yang diberikan pada sebuah objek.', 197 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
198 |
199 | console.log(o);`, 200 | output: `Object {
201 |   configurable: true,
202 |   enumerable: true,
203 |   value: 1,
204 |   writable: true
205 | }` 206 | }, 207 | { 208 | name: 'getOwnPropertyDescriptors', 209 | shortDesc: `detil-detil mengenai seluruh properti pada sebuah objek`, 210 | desc: 211 | 'Mengembalikan sebuah objek yang berisi seluruh deskriptor properti untuk sebuah objek.', 212 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 213 | output: `Object {
214 |   a: Object {
215 |     configurable: true,
216 |     enumerable: true,
217 |     value: 1,
218 |     writable: true
219 |   },
220 |   b: Object {
221 |     configurable: true,
222 |     enumerable: true,
223 |     value: 2,
224 |     writable: true
225 |   },
226 |   c: Object {
227 |     configurable: true,
228 |     enumerable: true,
229 |     value: 3,
230 |     writable: true
231 |   },
232 | }` 233 | }, 234 | { 235 | name: 'propertyIsEnumerable', 236 | shortDesc: `apakah sebuah properti dapat dilintasi dengan sebuah for...in loop`, 237 | desc: 238 | 'Mengembalikan sebuah boolean yang mengindikasikan apakah atribut internal ECMAScript [[Enumerable]] ditentukan. Metode ini dapat digunakan untuk melihat apakah suatu metode merupakan metode built-in atau user-defined, karena properti-properti built-in cenderung tidak enumerable.', 239 | example: `console.log(obj.propertyIsEnumerable('a'));
240 | console.log(Math.propertyIsEnumerable('random'));`, 241 | output: `true
242 | false` 243 | }, 244 | { 245 | name: 'hasOwnProperty', 246 | shortDesc: `apakah sebuah properti ada sebagai properti langsung dari sebuah objek`, 247 | desc: 248 | 'Mengembalikan sebuah boolean yang mengindikasikan apakah sebuah objek mengandung properti yang ditentukan sebagai suatu properti langsung dari objek tersebut dan tidak diwariskan melalui rantai prototipe (prototype chain).', 249 | example: `console.log(obj.hasOwnProperty('a'));
250 | delete obj.a;
251 | console.log(obj.hasOwnProperty('a'));`, 252 | output: `true
253 | false` 254 | } 255 | ], 256 | list: [ 257 | { 258 | name: 'keys', 259 | shortDesc: `kunci`, 260 | desc: `Mengembalikan sebuah array yang berisi nama-nama dari seluruh kunci milik objek yang dapat ditelusuri, dalam urutan ketika kunci-kunci tersebut ditelusuri.`, 261 | example: `console.log(Object.keys(obj));`, 262 | output: `["a", "b", "c"]` 263 | }, 264 | { 265 | name: 'values', 266 | shortDesc: `nilai`, 267 | desc: `Mengembalikan sebuah array yang berisi nama-nama dari seluruh nilai milik objek yang dapat ditelusuri, dalam urutan ketika nilai-nilai tersebut ditelusuri.`, 268 | example: `console.log(Object.values(obj));`, 269 | output: `[1, 2, 3]` 270 | }, 271 | { 272 | name: 'entries', 273 | shortDesc: `kunci dan nilai`, 274 | desc: `Mengembalikan sebuah nested array berisi nama-nama seluruh pasangan kunci/nilai dari objek yang dapat ditelusuri, dalam urutan ketika pasangan-pasangan tersebut ditelusuri.`, 275 | example: `console.log(Object.entries(obj));`, 276 | output: `[["a", 1], ["b", 2], ["c", 3]]` 277 | }, 278 | { 279 | name: 'getOwnPropertyNames', 280 | shortDesc: `kunci, meskipun Anda tidak dapat menelusuri kunci-kunci tersebut`, 281 | desc: `Mengembalikan sebuah array berisi nama-nama seluruh properti objek yang diberikan yang bersifat enumerable maupun non-enumerable. Metode ini melakukan hal yang sama seperti Object.keys(), yaitu mengambil seluruh kunci-kunci di objek, namun getOwnPropertyNames() juga mengikutsertakan properti-properti yang tidak bisa ditelusuri.`, 282 | example: `Object.defineProperty(obj, 'a', {
283 |   enumerable: false
284 | });
285 |
286 | console.log(Object.keys(obj));
287 | console.log(Object.getOwnPropertyNames(obj));`, 288 | output: `["b", "c"]
289 | ["a", "b", "c"]` 290 | } 291 | ] 292 | }, 293 | prototype: [ 294 | { 295 | name: 'getPrototypeOf', 296 | shortDesc: `mendapatkan sebuah prototipe dari objek`, 297 | desc: `Mengembalikan prototipe dari objek yang ditentukan (nilai dari properti internal [[Prototype]]) dari objek yang ditentukan).`, 298 | example: `const proto = Object.create(obj);
299 | console.log(Object.getPrototypeOf(proto) === obj);`, 300 | output: `true` 301 | }, 302 | { 303 | name: 'setPrototypeOf', 304 | shortDesc: `menentukan prototipe dari objek`, 305 | desc: `Peringatan: metode ini sangatlah. Gunakan dengan hati-hati, atau ganti dengan Object.create(). Metode ini menentukan the prototipe (properti internal [[Prototype]]).`, 306 | example: `const dict = Object.setPrototypeOf({}, obj);
307 |
308 | console.log(dict);`, 309 | output: `Object {
310 |   a: 1,
311 |   b: 2,
312 |   c: 3
313 | }` 314 | }, 315 | { 316 | name: 'isPrototypeOf', 317 | shortDesc: `menemukan apakah sebuah objek ada pada rantai prototipe`, 318 | desc: `Mengembalikan sebuah boolean yang mengindikasikan apakah objek di mana metode ini dipanggil ada pada sebuah rantai prototipe (prototype chain) dari objek yang ditentukan.`, 319 | example: `function Rect() {}
320 |
321 | var rect = new Rect();
322 |
323 | console.log(Rect.prototype.isPrototypeOf(rect));`, 324 | output: `true` 325 | } 326 | ] 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bg: require('./bg'), 3 | cz: require('./cz'), 4 | de: require('./de'), 5 | en: require('./en'), 6 | es: require('./es'), 7 | fr: require('./fr'), 8 | id: require('./id'), 9 | it: require('./it'), 10 | nl: require('./nl'), 11 | pt_pt: require('./pt_pt'), 12 | ru: require('./ru'), 13 | zh_cn: require('./zh_cn'), 14 | zh_hk: require('./zh_hk') 15 | } 16 | -------------------------------------------------------------------------------- /src/store/it.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'creare un nuovo oggetto', 8 | desc: `Crea un nuovo oggetto a partire dal prototipo e dalle proprietà specificate.
9 |
10 | Nota per i principianti! Solitamente gli oggetti si creano com'è mostrato all'inizio dell'esempio, così: let obj = { a: 1 };.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'copiare un oggetto', 22 | desc: 23 | `Copia i valori di tutte le proprietà enumerabili direttamente appartenenti a uno o più oggetti verso un oggetto di destinazione (il primo parametro). Restituisce l'oggetto di destinazione.
24 | Anche se tecnicamente non è una funzione degli oggetti, quando si usa ES6 è più comune usare lo Spread Operator, con l'operatore ....`, 25 | example: `const copia = Object.assign({}, obj);
26 | console.log(copia);`, 27 | output: `Object {
28 |   a: 1,
29 |   b: 2,
30 |   c: 3
31 | }` 32 | } 33 | ], 34 | createProp: [ 35 | { 36 | name: 'defineProperty', 37 | shortDesc: 'una nuova proprietà o modificarne una esistente', 38 | desc: `Aggiunge la proprietà specificata descritta dalle opzioni specificate a un oggetto.
39 |
40 | Nota per i principianti! Solitamente si usano il punto o le parentesi quadre per creare o modificare una proprietà, così: obj.a = 1 o obj[a] = 1. Tecnicamente questa non è una funzione, quindi non è includa nella lista.`, 41 | example: `Object.defineProperty(obj, 'd', {
42 |   enumerable: true,
43 |   configurable: true,
44 |   writable: true,
45 |   value: 4
46 | });
47 |
48 | console.log(obj.d);`, 49 | output: `4` 50 | }, 51 | { 52 | name: 'defineProperties', 53 | shortDesc: 'una o più nuova proprietà o modificarne di esistenti', 54 | desc: `Aggiunge le proprietà specificate descritta dalle opzioni specificate a un oggetto.
55 |
56 | Nota per i principianti! Solitamente si usano il punto o le parentesi quadre per creare o modificare una proprietà, così: obj.a = 1 o obj[a] = 1. Tecnicamente questa non è una funzione, quindi non è includa nella lista.`, 57 | example: `Object.defineProperties(obj, {
58 |   d: {
59 |     value: 4,
60 |     writable: true
61 |   },
62 |   e: {
63 |     value: 5,
64 |     writable: true
65 |   }
66 | });
67 |
68 | console.log(obj);`, 69 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 70 | } 71 | ], 72 | infoObj: [ 73 | { 74 | name: 'isExtensible', 75 | shortDesc: 'possono essere aggiunte nuove proprietà', 76 | desc: 77 | "Determina se è possibile estendere l'oggetto, ossia definirne nuove propretà.", 78 | example: `console.log(Object.isExtensible(obj));
79 | Object.freeze(obj);
80 | console.log(Object.isExtensible(obj));`, 81 | output: `true
82 | false` 83 | }, 84 | { 85 | name: 'is', 86 | shortDesc: 'due riferimenti rappresentano lo stesso oggetto', 87 | desc: 88 | `Determina se due riferimenti rappresentano lo stesso oggetto. Considera uguali tutti i valori NaN (che vengono considerati diversi sia dall'operatore == che ===). Questo è leggermente unusuale, e la documentazione su MDN è poco chiara. È più comodo utilizzare tre uguali === per controllare l'ugualianza tra oggetti.`, 89 | example: `let obj2 = {
90 |   a: 1,
91 |   b: 2,
92 |   c: 3
93 | };
94 |
95 | console.log(Object.is(obj, obj2));
96 | console.log(Object.is(obj, obj));`, 97 | output: `false
98 | true` 99 | }, 100 | { 101 | name: 'isFrozen', 102 | shortDesc: `un oggetto e le sue proprietà non possono essere modificati`, 103 | desc: 'Determina se un oggetto è congelato.', 104 | example: `console.log(Object.isFrozen(obj));
105 | Object.freeze(obj);
106 | console.log(Object.isFrozen(obj));`, 107 | output: `false
108 | true` 109 | }, 110 | { 111 | name: 'isSealed', 112 | shortDesc: `un oggetto non può essere modificato (ma le sue proprietà si)`, 113 | desc: 114 | 'Determina se non si possono aggiungere o togliere proprietà a un oggetto, e le descrizioni di quelle già esistenti non possono essere modificate.', 115 | example: `Object.seal(obj);
116 |
117 | console.log(Object.isSealed(obj));`, 118 | output: `true` 119 | }, 120 | { 121 | name: 'isPrototypeOf', 122 | shortDesc: `un oggetto è prototipo di un altro`, 123 | desc: `Restituisce true o false per indicare se l'oggetto del quale viene richiamato questo metodo + nella catena dei prorotipi dell'oggetto specificato.`, 124 | example: `function Rect() {}
125 |
126 | var rect = new Rect();
127 |
128 | console.log(Rect.prototype.isPrototypeOf(rect));`, 129 | output: `true`, 130 | useExample: 'newExample' 131 | } 132 | ], 133 | noChange: [ 134 | { 135 | name: 'seal', 136 | shortDesc: `evitare che vengano aggiunte o eliminate delle proprietà`, 137 | desc: 138 | "Evita che altro codice aggiunga o tolga proprietà all'oggetto specificato. Le proprietà già esistenti possono essere modificate ma non può essere modificata la loro descrizione.", 139 | example: `Object.seal(obj);
140 | delete obj.c;
141 |
142 | console.log(obj);`, 143 | output: `{a: 1, b: 2, c: 3} // obj.c non viene cancellata` 144 | }, 145 | { 146 | name: 'freeze', 147 | shortDesc: `evitare che vengano aggiunte, eliminate o modificate delle proprietà`, 148 | desc: `Congela un oggetto: non vi si possono più aggiungere, eliminare o modificare proprietà.`, 149 | example: `Object.freeze(obj);
150 | obj.a = 10;
151 |
152 | console.log(obj.a);`, 153 | output: `1 // il valore non è diventato 10` 154 | }, 155 | { 156 | name: 'preventExtensions', 157 | shortDesc: `evitare che vengano aggiunte nuove proprietà.`, 158 | desc: `Evita che un oggetto venga esteso. È comunque possibile cancellare proprietà esistenti.`, 159 | example: `Object.preventExtensions(obj);
160 | obj.d = 4;
161 |
162 | console.log(obj.d);`, 163 | output: `undefined` 164 | } 165 | ], 166 | createString: [ 167 | { 168 | name: 'toString', 169 | shortDesc: `una stringa che rappresenti l'oggetto.`, 170 | desc: `La funzione toString() restiuisce una stringa che rappresenta l'oggetto.
171 | Anche se questo è il metodo specifico di Object, è più utile usare JSON.stringify().`, 172 | example: `console.log(obj.toString());
173 | console.log(obj.a.toString());`, 174 | output: `"[object Object]"
175 | "1"` 176 | }, 177 | { 178 | name: 'toLocaleString', 179 | shortDesc: `una stringa localizzata che rappresenti l'oggetto.`, 180 | desc: `La funzione toLocaleString() restiuisce una stringa localizzata che rappresenta l'oggetto. 181 | Questo metodo solitamente viene sovrascritto dagli oggetti per comportarsi in base alla lingua. In parole povere: se si lavora con qualcosa che contiene dati diversi in base alla lingua, come le date, genererà un output diverso.`, 182 | example: `obj.d = new Date();
183 |
184 | console.log(obj.d);
185 | console.log(obj.d.toLocaleString());`, 186 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
187 | 3/1/2018, 14:54:33` 188 | } 189 | ], 190 | infoProp: { 191 | details: [ 192 | { 193 | name: 'getOwnPropertyDescriptor', 194 | shortDesc: `dettagli riguardo una proprietà di un oggetto`, 195 | desc: 196 | 'Restituisce un oggetto che descive una proprietà di un oggetto, dato il suo nome.', 197 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
198 |
199 | console.log(o);`, 200 | output: `Object {
201 |   configurable: true,
202 |   enumerable: true,
203 |   value: 1,
204 |   writable: true
205 | }` 206 | }, 207 | { 208 | name: 'getOwnPropertyDescriptors', 209 | shortDesc: `dettagli riguardo tutte le proprietà di un oggetto`, 210 | desc: 211 | "Restituisce un oggetto contenente le descrizioni di tutte le proprietà dell'oggetto specificato.", 212 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 213 | output: `Object {
214 |   a: Object {
215 |     configurable: true,
216 |     enumerable: true,
217 |     value: 1,
218 |     writable: true
219 |   },
220 |   b: Object {
221 |     configurable: true,
222 |     enumerable: true,
223 |     value: 2,
224 |     writable: true
225 |   },
226 |   c: Object {
227 |     configurable: true,
228 |     enumerable: true,
229 |     value: 3,
230 |     writable: true
231 |   },
232 | }` 233 | }, 234 | { 235 | name: 'propertyIsEnumerable', 236 | shortDesc: `se una proprietà viene visitata con un ciclo for...in`, 237 | desc: 238 | "Restituisce true o false per indicare se l'attributo interno di ECMAScript [[Enumerable]] è imopstato a true. Questa funzione può essere usata per sapere se una proprietà e predefinita o no, perché solitamente le proprietà predefinite non sono enumerabili.", 239 | example: `console.log(obj.propertyIsEnumerable('a'));
240 | console.log(Math.propertyIsEnumerable('random'));`, 241 | output: `true
242 | false` 243 | }, 244 | { 245 | name: 'hasOwnProperty', 246 | shortDesc: `se un ogetto ha direttamente una proprietà`, 247 | desc: 248 | 'Restituisce true o false per indicare se un oggetto contiene la proprietà specificata direttamente, e non tamite il suo prototipo.', 249 | example: `console.log(obj.hasOwnProperty('a'));
250 | delete obj.a;
251 | console.log(obj.hasOwnProperty('a'));`, 252 | output: `true
253 | false` 254 | } 255 | ], 256 | list: [ 257 | { 258 | name: 'keys', 259 | shortDesc: `le chiavi`, 260 | desc: `Restituisce un array che contiene i nomi di tutte le proprietà dell'oggetto che verrebbero visitate da un ciclo, nell'ordine in cui verrebbero visitate.`, 261 | example: `console.log(Object.keys(obj));`, 262 | output: `["a", "b", "c"]` 263 | }, 264 | { 265 | name: 'values', 266 | shortDesc: `i valori`, 267 | desc: `Restituisce un array che contiene i valori di tutte le proprietà dell'oggetto che verrebbero visitate da un ciclo, nell'ordine in cui verrebbero visitate.`, 268 | example: `console.log(Object.values(obj));`, 269 | output: `[1, 2, 3]` 270 | }, 271 | { 272 | name: 'entries', 273 | shortDesc: `le chiavi e i valori`, 274 | desc: `Restituisce un array che contiene le coppie nome/valore di tutte le proprietà dell'oggetto che verrebbero visitate da un ciclo, nell'ordine in cui verrebbero visitate.`, 275 | example: `console.log(Object.entries(obj));`, 276 | output: `[["a", 1], ["b", 2], ["c", 3]]` 277 | }, 278 | { 279 | name: 'getOwnPropertyNames', 280 | shortDesc: `le chiavi, anche se non verrebbero visitate da un ciclo`, 281 | desc: `Restituisce un array che contiene i nomi di tutte le proprietà dell'oggetto specificato. È simile a Object.keys(), ma Object.getOwnPropertyNames() restituisce anche le proprietà che non verrebero visitate da un ciclo for...in.`, 282 | example: `Object.defineProperty(obj, 'a', {
283 |   enumerable: false
284 | });
285 |
286 | console.log(Object.keys(obj));
287 | console.log(Object.getOwnPropertyNames(obj));`, 288 | output: `["b", "c"]
289 | ["a", "b", "c"]` 290 | } 291 | ] 292 | }, 293 | prototype: [ 294 | { 295 | name: 'getPrototypeOf', 296 | shortDesc: `leggere il prototipo di un oggetto.`, 297 | desc: `Restituisce il prototipo dell'oggetto specificato (quindi il valore della proprietà interna [[Prototype]]).`, 298 | example: `const proto = Object.create(obj);
299 | console.log(Object.getPrototypeOf(proto) === obj);`, 300 | output: `true` 301 | }, 302 | { 303 | name: 'setPrototypeOf', 304 | shortDesc: `impostare il prototipo di un oggetto.`, 305 | desc: `Attenzione: questa funzione è molto lenta. Se possibile, utilizzare Object.create().
306 |
Imposta il prototipo di un oggetto (la sua proprietà interna [[Prototype]]).`, 307 | example: `const dict = Object.setPrototypeOf({}, obj);
308 |
309 | console.log(dict);`, 310 | output: `Object {
311 |   a: 1,
312 |   b: 2,
313 |   c: 3
314 | }` 315 | }, 316 | { 317 | name: 'isPrototypeOf', 318 | shortDesc: `sapere se un oggetto è prototipo di un altro.`, 319 | desc: `Restituisce true o false per indicare se l'oggetto del quale viene richiamato questo metodo è nella catena dei prorotipi dell'oggetto specificato.`, 320 | example: `function Rect() {}
321 |
322 | var rect = new Rect();
323 |
324 | console.log(Rect.prototype.isPrototypeOf(rect));`, 325 | output: `true`, 326 | useExample: 'newExample' 327 | } 328 | ] 329 | } 330 | } 331 | -------------------------------------------------------------------------------- /src/store/nl.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'een nieuw object aanmaken', 8 | desc: `Maakt een nieuw object aan met het gekozen prototype object en properties.
9 |
10 | Belangrijke opmerking voor beginners! Het is gewoonlijk om een object te maken op de manier die boveaan gebruikt wordt, door een object aan een variabele toe te wijzen.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'een kopie van een object maken', 22 | desc: 23 | 'Kopieert de waardes van alle eigen telbare properties van een of meerdere source objecten naar een aangewezen object. Het geeft het aangewezen object terug.', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 'een nieuwe property of het aanpassen van een bestaande', 37 | desc: `Voegt een benoemde property, beschreven door een gegeven descriptor, toe aan een object .
38 |
39 | Belangrijke opmerking voor beginners! Het is gebruikelijk om dot of square brackets notatie te gebruiken bij het aanmaken van een nieuwe of bij het bewerken van een bestaande property. Zoals: obj.a = 1 of obj[a] = 1. Dit is technisch gezien geen ingebouwde methode, daarom staat dit ook niet beschreven.`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: 53 | 'een of meerdere properties of aanpassen van bestaande properties', 54 | desc: `Voegt een of meerdere properties, beschreven door een gegeven descriptor, toe aan een object
55 |
56 | Belangrijke opmerking voor beginners! Het is gebruikelijk om dot of square brackets notatie te gebruiken bij het aanmaken van een nieuwe of bij het bewerken van een bestaande property. Zoals: obj.a = 1 of obj[a] = 1. Dit is technisch gezien geen ingebouwde methode, daarom staat dit ook niet beschreven.`, 57 | example: `Object.defineProperties(obj, {
58 |   d: {
59 |     value: 4,
60 |     writable: true
61 |   },
62 |   e: {
63 |     value: 5,
64 |     writable: true
65 |   }
66 | });
67 |
68 | console.log(obj);`, 69 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 70 | } 71 | ], 72 | infoObj: [ 73 | { 74 | name: 'isExtensible', 75 | shortDesc: 'of er meer properties toegevoegd kunnen worden', 76 | desc: 'Bepaald of uitbreiding van een object toegestaan is.', 77 | example: `console.log(Object.isExtensible(obj));
78 | Object.freeze(obj);
79 | console.log(Object.isExtensible(obj));`, 80 | output: `true
81 | false` 82 | }, 83 | { 84 | name: 'is', 85 | shortDesc: 'of twee referenties naar hetzelfde object wijzen', 86 | desc: 87 | 'Vergelijkt of twee referenties naar hetzelfde object wijzen. Het staat gelijk aan NaN waardes (Welke verschillen van zowel Abstract Equality Comparison en Strict Equality Comparison). Dit is een gekke, ook is de MDN documentatie een beetje misleidend.', 88 | example: `let obj2 = {
89 |   a: 1,
90 |   b: 2,
91 |   c: 3
92 | };
93 |
94 | console.log(Object.is(obj, obj2));
95 | console.log(Object.is(obj, obj));`, 96 | output: `false
97 | true` 98 | }, 99 | { 100 | name: 'isFrozen', 101 | shortDesc: `of een object en de properties niet bewerkt kunnen worden`, 102 | desc: 'Bepaald of een object bevroren is.', 103 | example: `console.log(Object.isFrozen(obj));
104 | Object.freeze(obj);
105 | console.log(Object.isFrozen(obj));`, 106 | output: `false
107 | true` 108 | }, 109 | { 110 | name: 'isSealed', 111 | shortDesc: `of een object niet bewerkt kan worden (maar de properties wel)`, 112 | desc: 'Bepaald of een object of de properties zijn afgesloten.', 113 | example: `Object.seal(obj);
114 |
115 | console.log(Object.isSealed(obj));`, 116 | output: `true` 117 | }, 118 | { 119 | name: 'isPrototypeOf', 120 | shortDesc: `of een object onder een prototype valt`, 121 | desc: `Geeft een boolean terug die aangeeft of de object die in de methode aangeroepen wordt onder de prototype valt van het gespecificeerde object.`, 122 | example: `function Rect() {}
123 |
124 | var rect = new Rect();
125 |
126 | console.log(Rect.prototype.isPrototypeOf(rect));`, 127 | output: `true`, 128 | useExample: 'newExample' 129 | } 130 | ], 131 | noChange: [ 132 | { 133 | name: 'seal', 134 | shortDesc: `zeker weten dat properties niet toegevoegd of verwijderd kunnen worden`, 135 | desc: 136 | 'Voorkomt dat andere code properties van een object kan verwijderen. Bestaande properties kunnen nog steeds bewerkt worden.', 137 | example: `Object.seal(obj);
138 | delete obj.c;
139 |
140 | console.log(obj);`, 141 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 142 | }, 143 | { 144 | name: 'freeze', 145 | shortDesc: `zeker weten dat properties niet toegevoegd, verwijderd of bewerkt kunnen worden`, 146 | desc: `Bevriesd een object: andere code kan geen properties bewerken of verwijderen.`, 147 | example: `Object.freeze(obj);
148 | obj.a = 10;
149 |
150 | console.log(obj.a);`, 151 | output: `1 //the value didn't update to 10` 152 | }, 153 | { 154 | name: 'preventExtensions', 155 | shortDesc: `zeker weten dat properties niet toegevoegd kunnen worden`, 156 | desc: `Voorkomt uitbreiding van een object. Ik kan nog steeds properties verwijderen maar ik kan geen nieuwe toevoegen.`, 157 | example: `Object.preventExtensions(obj);
158 | obj.d = 4;
159 |
160 | console.log(obj.d);`, 161 | output: `undefined` 162 | } 163 | ], 164 | createString: [ 165 | { 166 | name: 'toString', 167 | shortDesc: `een object in de vorm van een string`, 168 | desc: `de toString() methode rgeeft een object terug in de vorm van een string.`, 169 | example: `console.log(obj.toString());
170 | console.log(obj.a.toString());`, 171 | output: `"[object Object]"
172 | "1"` 173 | }, 174 | { 175 | name: 'toLocaleString', 176 | shortDesc: `een object in de vorm van een taalstring`, 177 | desc: `De toLocaleString() methode geeft een object terug in de vorm van een string. Deze methode is bedoeld om overschreven te worden bij een afgeleid object voor taal-specifieke doeleinde. In mensen taal: dit betekent dat als je iets hebt dat andere data heeft op basis van locatie, zoals een data methode, het jou een ander tijd format geeft.`, 178 | example: `obj.d = new Date();
179 |
180 | console.log(obj.d);
181 | console.log(obj.d.toLocaleString());`, 182 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
183 | 12/29/2017, 8:57:35 PM` 184 | } 185 | ], 186 | infoProp: { 187 | details: [ 188 | { 189 | name: 'getOwnPropertyDescriptor', 190 | shortDesc: `details over een property`, 191 | desc: 192 | 'Geeft een property descriptor voor een benoemde property van een object.', 193 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
194 |
195 | console.log(o);`, 196 | output: `Object {
197 |   configurable: true,
198 |   enumerable: true,
199 |   value: 1,
200 |   writable: true
201 | }` 202 | }, 203 | { 204 | name: 'getOwnPropertyDescriptors', 205 | shortDesc: `details over alle properties van een object`, 206 | desc: 207 | 'Geeft een object terug bestaande uit alle eigen property descriptors van een object', 208 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 209 | output: `Object {
210 |   a: Object {
211 |     configurable: true,
212 |     enumerable: true,
213 |     value: 1,
214 |     writable: true
215 |   },
216 |   b: Object {
217 |     configurable: true,
218 |     enumerable: true,
219 |     value: 2,
220 |     writable: true
221 |   },
222 |   c: Object {
223 |     configurable: true,
224 |     enumerable: true,
225 |     value: 3,
226 |     writable: true
227 |   },
228 | }` 229 | }, 230 | { 231 | name: 'propertyIsEnumerable', 232 | shortDesc: `of een property doorlopen kan worden met een for...in loop `, 233 | desc: 234 | 'Geeft een boolean terug die aangeeft of de interne ECMAScript [[Enumerable]] attribute actief is. Dit kan gebruikt worden of iets een standaard methode is of een gebruikers methode is, omdat standaard properties normaal gesproken niet telbaar zijn.', 235 | example: `console.log(obj.propertyIsEnumerable('a'));
236 | console.log(Math.propertyIsEnumerable('random'));`, 237 | output: `true
238 | false` 239 | }, 240 | { 241 | name: 'hasOwnProperty', 242 | shortDesc: `of een property bestaat als een directe property van het object`, 243 | desc: 244 | 'Geeft een boolean terug die aangeeft of een object bestaat uit een specifieke property als een directe property van dat object en dus niet geërfd is van de overkoepelende prototype.', 245 | example: `console.log(obj.hasOwnProperty('a'));
246 | delete obj.a;
247 | console.log(obj.hasOwnProperty('a'));`, 248 | output: `true
249 | false` 250 | } 251 | ], 252 | list: [ 253 | { 254 | name: 'keys', 255 | shortDesc: `sleutels`, 256 | desc: `Geeft een array terug bestaande uit alle namen van alle object sleutels waar doorheen gelooped kan worden, in de volgorde dat deze doorgeloopt zou worden.`, 257 | example: `console.log(Object.keys(obj));`, 258 | output: `["a", "b", "c"]` 259 | }, 260 | { 261 | name: 'values', 262 | shortDesc: `waardes`, 263 | desc: `Geeft een array terug bestaande uit alle namen van alle object waardes waar doorheen gelooped kan worden, in de volgorde dat deze doorgeloopt zou worden.`, 264 | example: `console.log(Object.values(obj));`, 265 | output: `[1, 2, 3]` 266 | }, 267 | { 268 | name: 'entries', 269 | shortDesc: `sleutels en waardes`, 270 | desc: `Geeft een genestelde array terug bestaande uit alle namen van alle object sleutel/waarde paren waar doorheen gelooped kan worden, in de volgorde dat deze doorgeloopt zou worden.`, 271 | example: `console.log(Object.entries(obj));`, 272 | output: `[["a", 1], ["b", 2], ["c", 3]]` 273 | }, 274 | { 275 | name: 'getOwnPropertyNames', 276 | shortDesc: `sleutels, ookal kan je er niet doorheen loopen`, 277 | desc: `Geeft een array terug bestaande uit alle namen van alle object properties, zowel telbaar als niet telbaar. Doet het zelfde als Object.keys(), verkrijgen van de sleutels in het object, maar getOwnPropertyNames() bevat ook properties waar niet doorheen gelooped kan worden.`, 278 | example: `Object.defineProperty(obj, 'a', {
279 |   enumerable: false
280 | });
281 |
282 | console.log(Object.keys(obj));
283 | console.log(Object.getOwnPropertyNames(obj));`, 284 | output: `["b", "c"]
285 | ["a", "b", "c"]` 286 | } 287 | ] 288 | }, 289 | prototype: [ 290 | { 291 | name: 'getPrototypeOf', 292 | shortDesc: `een prototype van een object verkrijgen`, 293 | desc: `Geeft de prototype terug van het gespecificeerde object. Dat is de waarde van de interne [[Prototype]] property van het gespecificeerde object.`, 294 | example: `const proto = Object.create(obj);
295 | console.log(Object.getPrototypeOf(proto) === obj);`, 296 | output: `true` 297 | }, 298 | { 299 | name: 'setPrototypeOf', 300 | shortDesc: `een prototype voor het object toewijzen`, 301 | desc: `Waarschuwing: deze methode is erg sloom. Gebruik dit voorzichtig, of vervang door Object.create(). Het wijst een prototype (dat is de interne[[Prototype]] property) toe.`, 302 | example: `const dict = Object.setPrototypeOf({}, obj);
303 |
304 | console.log(dict);`, 305 | output: `Object {
306 |   a: 1,
307 |   b: 2,
308 |   c: 3
309 | }` 310 | }, 311 | { 312 | name: 'isPrototypeOf', 313 | shortDesc: `uitzoeken of een object onder een prototype valt`, 314 | desc: `Geeft een boolean terug die aangeeft of het object van deze methode die aangeroepen wordt onder de prototype valt van het gespecificeerde object.`, 315 | example: `function Rect() {}
316 |
317 | var rect = new Rect();
318 |
319 | console.log(Rect.prototype.isPrototypeOf(rect));`, 320 | output: `true` 321 | } 322 | ] 323 | } 324 | } 325 | -------------------------------------------------------------------------------- /src/store/pt_pt.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'cria um novo objecto', 8 | desc: `Cria um novo objecto com o objecto e propriedades do protótipo especificado.
9 |
10 | Nota importante para iniciantes! È mais comum criar um objecto da maneira demonstrada na parte de cima do exemplo, assim. let obj = { a: 1 };`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'fazer uma cópia do objecto', 22 | desc: 23 | 'Copia os valores de todas as propriedades de um ou mais objectos para um objecto novo. Retorna esse novo objecto. Enquanto tecnicamente não é um método nativo de objectos, é mais comum usar o Spread Operator em ES6 com ...', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: 'uma nova propriadade ou mudar uma existente', 37 | desc: `Adiciona a propriadade descrita pelo descritor a um objecto
38 |
39 | Nota importante para iniciantes! È mais comum usar pontos finais ou parênteses rectos para criar uma nova propriadade num objecto ou modificar uma ja existente. Assim: obj.a = 1 or obj[a] = 1. Mas tecnicamente isto não é um metodo incluido nos objectos por isso nao esta incluido`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: 53 | 'uma ou mais novas propriedades ou mudar uma ou mais propriedades existentes', 54 | desc: `Adiciona uma ou mais propriedades descritas pelo descritor a um objecto
55 |
56 | Nota importante para iniciantes! È mais comum usar pontos finais ou parênteses rectos para criar uma nova propriadade num objecto ou modificar uma ja existente. Assim: obj.a = 1 or obj[a] = 1. Mas tecnicamente isto não é um metodo incluido nos objectos por isso nao esta incluido`, 57 | example: `Object.defineProperties(obj, {
58 |   d: {
59 |     value: 4,
60 |     writable: true
61 |   },
62 |   e: {
63 |     value: 5,
64 |     writable: true
65 |   }
66 | });
67 |
68 | console.log(obj);`, 69 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 70 | } 71 | ], 72 | infoObj: [ 73 | { 74 | name: 'isExtensible', 75 | shortDesc: 'se mais propriedades podem ser adicionadas', 76 | desc: 77 | 'Determina se mais propriedades podem ser adicionadas a um objecto.', 78 | example: `console.log(Object.isExtensible(obj));
79 | Object.freeze(obj);
80 | console.log(Object.isExtensible(obj));`, 81 | output: `true
82 | false` 83 | }, 84 | { 85 | name: 'is', 86 | shortDesc: 'se duas referências apontam para o mesmo obejcto', 87 | desc: 88 | 'Compara duas refereências e vê se ambas apontam para o mesmo objecto. Iguala todos os valores NaN também. Esta é um bocado estranha e a documentação da Mozilla é um bocado enganadora. È mais util usar três iguais === para verificar isto.', 89 | example: `let obj2 = {
90 |   a: 1,
91 |   b: 2,
92 |   c: 3
93 | };
94 |
95 | console.log(Object.is(obj, obj2));
96 | console.log(Object.is(obj, obj));`, 97 | output: `false
98 | true` 99 | }, 100 | { 101 | name: 'isFrozen', 102 | shortDesc: `se um objecto e as suas propriedades não podem ser modificadas`, 103 | desc: 'Determina se um objecto está congelado', 104 | example: `console.log(Object.isFrozen(obj));
105 | Object.freeze(obj);
106 | console.log(Object.isFrozen(obj));`, 107 | output: `false
108 | true` 109 | }, 110 | { 111 | name: 'isSealed', 112 | shortDesc: `se um objecto não pode ser modificado (mas as suas propriedades podem)`, 113 | desc: 'Determina se um objecto ou as suas propriedades estão seladas', 114 | example: `Object.seal(obj);
115 |
116 | console.log(Object.isSealed(obj));`, 117 | output: `true` 118 | }, 119 | { 120 | name: 'isPrototypeOf', 121 | shortDesc: `se o objecto está na cadeia de protótipos.`, 122 | desc: `Retorna verdadeiro ou falso dependendo de este método ser chamado ou não na cadeia de protótipos do objecto especificado.`, 123 | example: `function Rect() {}
124 |
125 | var rect = new Rect();
126 |
127 | console.log(Rect.prototype.isPrototypeOf(rect));`, 128 | output: `true`, 129 | useExample: 'newExample' 130 | } 131 | ], 132 | noChange: [ 133 | { 134 | name: 'seal', 135 | shortDesc: `definir que não se pode adicionar ou remover propriedades deste objecto`, 136 | desc: 137 | 'Evita que outro código apague propriedades a um objecto. Propriedades já existentes podem ser modificadas normalmente.', 138 | example: `Object.seal(obj);
139 | delete obj.c;
140 |
141 | console.log(obj);`, 142 | output: `{a: 1, b: 2, c: 3} // obj.c não foi apagado` 143 | }, 144 | { 145 | name: 'freeze', 146 | shortDesc: `definir que não se pode adicionar, remover ou modificar propriedades deste objecto`, 147 | desc: `Congela um objecto: outro código não pode apagar ou modificar as propriedades deste objecto.`, 148 | example: `Object.freeze(obj);
149 | obj.a = 10;
150 |
151 | console.log(obj.a);`, 152 | output: `1 // o valor nao mudou para 10` 153 | }, 154 | { 155 | name: 'preventExtensions', 156 | shortDesc: `definir que não se pode adicionar propriedades a este objecto.`, 157 | desc: `Previne que se adicionem novas propriedades a um objecto. Continuas a poder apagar ou modificar as já existem.`, 158 | example: `Object.preventExtensions(obj);
159 | obj.d = 4;
160 |
161 | console.log(obj.d);`, 162 | output: `undefined` 163 | } 164 | ], 165 | createString: [ 166 | { 167 | name: 'toString', 168 | shortDesc: `representação do objecto em texto.`, 169 | desc: `O método toString() retorna a representação em texto do objecto. Apesar de este ser o método nativo de objectos é mais util usar JSON.stringify()`, 170 | example: `console.log(obj.toString());
171 | console.log(obj.a.toString());`, 172 | output: `"[object Object]"
173 | "1"` 174 | }, 175 | { 176 | name: 'toLocaleString', 177 | shortDesc: `representação do objecto em texto localizado.`, 178 | desc: `O método toLocaleString() retorna a representação em texto localizado do objecto. Esté metodo é suposto retornar coisas diferentes em ocasiões diferentes. Por exemplo se tiveres uma data guardada este método vai te retornar um formato de data diferente dependendo da tua localização.`, 179 | example: `obj.d = new Date();
180 |
181 | console.log(obj.d);
182 | console.log(obj.d.toLocaleString());`, 183 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
184 | 12/29/2017, 8:57:35 PM` 185 | } 186 | ], 187 | infoProp: { 188 | details: [ 189 | { 190 | name: 'getOwnPropertyDescriptor', 191 | shortDesc: `detalhes sobre uma propriedade`, 192 | desc: 193 | 'Retorna a descrição e caracteristicas da propriedade passada á função.', 194 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
195 |
196 | console.log(o);`, 197 | output: `Object {
198 |   configurable: true,
199 |   enumerable: true,
200 |   value: 1,
201 |   writable: true
202 | }` 203 | }, 204 | { 205 | name: 'getOwnPropertyDescriptors', 206 | shortDesc: `detalhes sobre todas as propriedades num objecto`, 207 | desc: 208 | 'Retorna um objecto que contêm a descrião e caracteristicas de todas as propriedades de um objecto', 209 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 210 | output: `Object {
211 |   a: Object {
212 |     configurable: true,
213 |     enumerable: true,
214 |     value: 1,
215 |     writable: true
216 |   },
217 |   b: Object {
218 |     configurable: true,
219 |     enumerable: true,
220 |     value: 2,
221 |     writable: true
222 |   },
223 |   c: Object {
224 |     configurable: true,
225 |     enumerable: true,
226 |     value: 3,
227 |     writable: true
228 |   },
229 | }` 230 | }, 231 | { 232 | name: 'propertyIsEnumerable', 233 | shortDesc: `se um propriadade pode ser enumerada através de um for...in loop`, 234 | desc: 235 | 'Retorna verdadeiro ou falso indicando se a propriadade interna do ECMAScript [[Enumerable]] está definida. Isto pode ser usado para ver se o objecto é algo da linguagem ou definido pelo utilizador porque propriedades definidas pela linguagem tendem a não ser enumeráveis.', 236 | example: `console.log(obj.propertyIsEnumerable('a'));
237 | console.log(Math.propertyIsEnumerable('random'));`, 238 | output: `true
239 | false` 240 | }, 241 | { 242 | name: 'hasOwnProperty', 243 | shortDesc: `se uma propriadade existe num objecto `, 244 | desc: 245 | 'Retorna verdadeiro ou falso dependendo se o objecto contêm a propriadade especificada como filho directo.', 246 | example: `console.log(obj.hasOwnProperty('a'));
247 | delete obj.a;
248 | console.log(obj.hasOwnProperty('a'));`, 249 | output: `true
250 | false` 251 | } 252 | ], 253 | list: [ 254 | { 255 | name: 'keys', 256 | shortDesc: `keys`, 257 | desc: `Retorna uma array com os nomes das keys que pode ser enumerada.`, 258 | example: `console.log(Object.keys(obj));`, 259 | output: `["a", "b", "c"]` 260 | }, 261 | { 262 | name: 'values', 263 | shortDesc: `valores`, 264 | desc: `Retorna uma array com os valores que pode ser enumerada.`, 265 | example: `console.log(Object.values(obj));`, 266 | output: `[1, 2, 3]` 267 | }, 268 | { 269 | name: 'entries', 270 | shortDesc: `keys e valores`, 271 | desc: 272 | 'Retorna uma array com arrays e dentro de cada uma temos a key e o valor de uma das propriedades do objecto.', 273 | example: `console.log(Object.entries(obj));`, 274 | output: `[["a", 1], ["b", 2], ["c", 3]]` 275 | }, 276 | { 277 | name: 'getOwnPropertyNames', 278 | shortDesc: `keys, mesmo que não as consigas enumerar`, 279 | desc: `Retorna uma array que contêem os nomes de todas as propriedades de um objecto mesmo que estas não sejam enumeráveis. Faz o mesmo que Object.keys(), devolvendo todas as keys de um objecto mas getOwnPropertyNames() inclui propriedades que nao podem ser enumeradas em loops.`, 280 | example: `Object.defineProperty(obj, 'a', {
281 |   enumerable: false
282 | });
283 |
284 | console.log(Object.keys(obj));
285 | console.log(Object.getOwnPropertyNames(obj));`, 286 | output: `["b", "c"]
287 | ["a", "b", "c"]` 288 | } 289 | ] 290 | }, 291 | prototype: [ 292 | { 293 | name: 'getPrototypeOf', 294 | shortDesc: `retornar o protótipo de um objecto.`, 295 | desc: `Retorna o protótipo de um objecto especificado. (o valor da propriadade interna [[Prototype]]).`, 296 | example: `const proto = Object.create(obj);
297 | console.log(Object.getPrototypeOf(proto) === obj);`, 298 | output: `true` 299 | }, 300 | { 301 | name: 'setPrototypeOf', 302 | shortDesc: `definir o protótipo do objecto.`, 303 | desc: `Atenção: este método é muito lento. Usar com caução ou substituir por Object.create(). Define o protótipo (o valor da propriadade interna [[Prototype]]).`, 304 | example: `const dict = Object.setPrototypeOf({}, obj);
305 |
306 | console.log(dict);`, 307 | output: `Object {
308 |   a: 1,
309 |   b: 2,
310 |   c: 3
311 | }` 312 | }, 313 | { 314 | name: 'isPrototypeOf', 315 | shortDesc: `descobre se o objecto está na cadeia de prototipos.`, 316 | desc: `Retorna verdadeiro ou falso indicando se o objecto que é usado neste método faz parte da cadeia de prototipos do objecto especificado.`, 317 | example: `function Rect() {}
318 |
319 | var rect = new Rect();
320 |
321 | console.log(Rect.prototype.isPrototypeOf(rect));`, 322 | output: `true` 323 | } 324 | ] 325 | } 326 | } 327 | -------------------------------------------------------------------------------- /src/store/ru.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: 'создать новый объект', 8 | desc: `Создает новый объект с указанным значением прототипа и свойствами объекта.
9 |
10 | Важное замечание для начинающих! Более часто используемый путь создания объекта представлен в начале примера, например так
let obj = { a: 1 };.`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: 'сделать копию существующего объекта', 22 | desc: `Копирует значений всех собственных перечисляемых свойств из одного или более исходных объектов в целевой объект. После копирования он возвращает целевой объект. Не смотря на то что Оператор расширения (Spread Operator) не является встроеным методом объекта, чаще всего в es6 синтаксисе используют его, для использования достаточно написать ...`, 23 | example: `const copy = Object.assign({}, obj);
24 | console.log(copy);`, 25 | output: `Object {
26 |   a: 1,
27 |   b: 2,
28 |   c: 3
29 | }` 30 | } 31 | ], 32 | createProp: [ 33 | { 34 | name: 'defineProperty', 35 | shortDesc: 'добавить новое свойство или изменить существующее', 36 | desc: `Определяет новое или изменяет существующее свойство непосредственно на объекте, возвращая этот объект.
37 |
38 | Важное замечание для начинающих! Чаще всего использую нотацию записи через точку или квадратные скобки для создания нового свойства или изменения существующего. К примеру: obj.a = 1 или obj[a] = 1. Это технически не встроеный метод языка поэтому здесь не рассмотрен.`, 39 | example: `Object.defineProperty(obj, 'd', {
40 |   enumerable: true,
41 |   configurable: true,
42 |   writable: true,
43 |   value: 4
44 | });
45 |
46 | console.log(obj.d);`, 47 | output: `4` 48 | }, 49 | { 50 | name: 'defineProperties', 51 | shortDesc: 'добавить или изменить существующие свойства объекта', 52 | desc: `Добавляет одно или несколько свойств, описываемых данным дескриптором объекта.
53 |
54 | Важное замечание для начинающих! Чаще всего использую нотацию записи через точку или квадратные скобки для создания нового свойства или изменения существующего. К примеру: obj.a = 1 or obj[a] = 1. Это технически не встроеный метод языка поэтому здесь не рассмотрен.`, 55 | example: `Object.defineProperties(obj, {
56 |   d: {
57 |     value: 4,
58 |     writable: true
59 |   },
60 |   e: {
61 |     value: 5,
62 |     writable: true
63 |   }
64 | });
65 |
66 | console.log(obj);`, 67 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 68 | } 69 | ], 70 | infoObj: [ 71 | { 72 | name: 'isExtensible', 73 | shortDesc: 'могут ли быть добавлены еще свойства', 74 | desc: 75 | 'Определяет, является ли объект расширяемым (то есть, можно ли к нему добавлять новые свойства).', 76 | example: `console.log(Object.isExtensible(obj));
77 | Object.freeze(obj);
78 | console.log(Object.isExtensible(obj));`, 79 | output: `true
80 | false` 81 | }, 82 | { 83 | name: 'is', 84 | shortDesc: 'являются ли два значения одинаковыми значениями', 85 | desc: 86 | `Сравнивает, если два значения указывают на один и тот же объект. Обозначает все значения NaN (которые отличаются как от сравнения абстрактного равенства, так и от строгого равенства). Это немного странно, и документация MDN вводит в заблуждение. Более правильный путь сравнивать два значения это использовать тройной знак равенства ===`, 87 | example: `let obj2 = {
88 |   a: 1,
89 |   b: 2,
90 |   c: 3
91 | };
92 |
93 | console.log(Object.is(obj, obj2));
94 | console.log(Object.is(obj, obj));`, 95 | output: `false
96 | true` 97 | }, 98 | { 99 | name: 'isFrozen', 100 | shortDesc: `что объект и его свойства не могут быть изменены`, 101 | desc: 102 | 'Определяет заморожен ли объект. Объект является замороженным только в том случае, если он не расширяем, все его свойства являются не настраиваемыми и все его свойства данных являются не записываемыми.', 103 | example: `console.log(Object.isFrozen(obj));
104 | Object.freeze(obj);
105 | console.log(Object.isFrozen(obj));`, 106 | output: `false
107 | true` 108 | }, 109 | { 110 | name: 'isSealed', 111 | shortDesc: `что объект не может быть изменен (хотя его свойства могут быть)`, 112 | desc: 113 | 'Определяет, является ли объект и его свойства запечатанными. Объект является запечатанным, если он является не расширяемым и если все его свойства являются не настраиваемыми и, следовательно, не удаляемыми (но не обязательно не записываемыми).', 114 | example: `Object.seal(obj);
115 |
116 | console.log(Object.isSealed(obj));`, 117 | output: `true` 118 | }, 119 | { 120 | name: 'isPrototypeOf', 121 | shortDesc: `входит ли объект в цепочку прототипов другого объекта.`, 122 | desc: `Возвращает логическое значение, указывающее, входит ли объект, вызываемый этим методом, в цепочку прототипов указанного объекта.`, 123 | example: `function Rect() {}
124 |
125 | var rect = new Rect();
126 |
127 | console.log(Rect.prototype.isPrototypeOf(rect));`, 128 | output: `true`, 129 | useExample: 'newExample' 130 | } 131 | ], 132 | noChange: [ 133 | { 134 | name: 'seal', 135 | shortDesc: `быть уверенным что свойства не будет добавленны или удалены`, 136 | desc: 137 | 'Предотвращает добавление новых свойств к объекту и делая все существующие свойства не настраиваемыми. Значения представленных свойств всё ещё могут изменяться, поскольку они остаются записываемыми.', 138 | example: `Object.seal(obj);
139 | delete obj.c;
140 |
141 | console.log(obj);`, 142 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 143 | }, 144 | { 145 | name: 'freeze', 146 | shortDesc: `быть уверенным что свойства не будут добавленны, удалены или модифицированны`, 147 | desc: `Замораживает объект: это значит, что он предотвращает добавление новых свойств к объекту, удаление старых свойств из объекта и изменение существующих свойств`, 148 | example: `Object.freeze(obj);
149 | obj.a = 10;
150 |
151 | console.log(obj.a);`, 152 | output: `1 //the value didn't update to 10` 153 | }, 154 | { 155 | name: 'preventExtensions', 156 | shortDesc: `быть уверенным что свойства не будут добавленны`, 157 | desc: `Предотврашает расширение объекта. По прежнему можно удалять свойства, но нельзя добавить ни одно.`, 158 | example: `Object.preventExtensions(obj);
159 | obj.d = 4;
160 |
161 | console.log(obj.d);`, 162 | output: `undefined` 163 | } 164 | ], 165 | createString: [ 166 | { 167 | name: 'toString', 168 | shortDesc: `строковое представление объекта.`, 169 | desc: `Метод toString() возвращает строку, представляющую объект. Не смотря на то что существует встроенный метод, на практике обычно используют JSON.stringify()`, 170 | example: `console.log(obj.toString());
171 | console.log(obj.a.toString());`, 172 | output: `"[object Object]"
173 | "1"` 174 | }, 175 | { 176 | name: 'toLocaleString', 177 | shortDesc: `локализованное строковое представление объекта.`, 178 | desc: `Метод toLocaleString() возвращает строку, представляющую объект. Этот метод предназначен для переопределения унаследованными объектами в целях поддержки зависимости от локали.`, 179 | example: `obj.d = new Date();
180 |
181 | console.log(obj.d);
182 | console.log(obj.d.toLocaleString());`, 183 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
184 | 12/29/2017, 8:57:35 PM` 185 | } 186 | ], 187 | infoProp: { 188 | details: [ 189 | { 190 | name: 'getOwnPropertyDescriptor', 191 | shortDesc: `информацию о свойстве объекта`, 192 | desc: 193 | 'Метод возвращает дескриптор свойства для собственного свойства переданного объекта', 194 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
195 |
196 | console.log(o);`, 197 | output: `Object {
198 |   configurable: true,
199 |   enumerable: true,
200 |   value: 1,
201 |   writable: true
202 | }` 203 | }, 204 | { 205 | name: 'getOwnPropertyDescriptors', 206 | shortDesc: `информацию о всех свойствах объекта`, 207 | desc: 208 | 'Возвращает объект, содержащий все собственные дескрипторы свойств для объекта.', 209 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 210 | output: `Object {
211 |   a: Object {
212 |     configurable: true,
213 |     enumerable: true,
214 |     value: 1,
215 |     writable: true
216 |   },
217 |   b: Object {
218 |     configurable: true,
219 |     enumerable: true,
220 |     value: 2,
221 |     writable: true
222 |   },
223 |   c: Object {
224 |     configurable: true,
225 |     enumerable: true,
226 |     value: 3,
227 |     writable: true
228 |   },
229 | }` 230 | }, 231 | { 232 | name: 'propertyIsEnumerable', 233 | shortDesc: `можно ли обойти содержимое свойства при помоши цикла for...in`, 234 | desc: 235 | 'Возврашает логичское значение идентифицируешее что выставлен внутренний атрибут (ECMAScript) [[Enumerable]]. Этот атрибут можно использовать, чтобы определить, является ли свойство объекта встроенным или методом определенным пользователем, так как встроенные свойства, как правило, не могут быть перечисляемыми.', 236 | example: `console.log(obj.propertyIsEnumerable('a'));
237 | console.log(Math.propertyIsEnumerable('random'));`, 238 | output: `true
239 | false` 240 | }, 241 | { 242 | name: 'hasOwnProperty', 243 | shortDesc: `что свойство существует как непосредственное свойство объекта`, 244 | desc: 245 | 'Возврашет логическое значение, указывающее, содержит ли объект указанное свойство и не наследует данное свойство через цепочку прототипов.', 246 | example: `console.log(obj.hasOwnProperty('a'));
247 | delete obj.a;
248 | console.log(obj.hasOwnProperty('a'));`, 249 | output: `true
250 | false` 251 | } 252 | ], 253 | list: [ 254 | { 255 | name: 'keys', 256 | shortDesc: `ключей`, 257 | desc: `Возврашает массив из собственных перечисляемых свойств объекта, в том же порядке, в котором они бы обходились циклом for...in.`, 258 | example: `console.log(Object.keys(obj));`, 259 | output: `["a", "b", "c"]` 260 | }, 261 | { 262 | name: 'values', 263 | shortDesc: `значений`, 264 | desc: `Возврашает массив из значений собственных перечисляемых свойств объекта, в том же порядке, в котором они бы обходились циклом for...in.`, 265 | example: `console.log(Object.values(obj));`, 266 | output: `[1, 2, 3]` 267 | }, 268 | { 269 | name: 'entries', 270 | shortDesc: `ключей и значений`, 271 | desc: `Возвращает вложенный массив, содержащий имена всех пар собственных перечисляемых свойств указанного объекта в формате [key, value], в том же порядке, что и в цикле for...in`, 272 | example: `console.log(Object.entries(obj));`, 273 | output: `[["a", 1], ["b", 2], ["c", 3]]` 274 | }, 275 | { 276 | name: 'getOwnPropertyNames', 277 | shortDesc: `ключи, в том числе не перечисляемые`, 278 | desc: `Возвращает массив со всеми свойствами (независимо от того, перечисляемые они или нет), найденными непосредственно в переданном объекте. такое же извлечение ключей в объект, что и Object.keys(), но getOwnPropertyNames() будет включать не перечисляемые свойства.`, 279 | example: `Object.defineProperty(obj, 'a', {
280 |   enumerable: false
281 | });
282 |
283 | console.log(Object.keys(obj));
284 | console.log(Object.getOwnPropertyNames(obj));`, 285 | output: `["b", "c"]
286 | ["a", "b", "c"]` 287 | } 288 | ] 289 | }, 290 | prototype: [ 291 | { 292 | name: 'getPrototypeOf', 293 | shortDesc: `получить прототип объекта.`, 294 | desc: `Возвращает прототип (то есть, внутреннее свойство [[Prototype]]) указанного объекта.`, 295 | example: `const proto = Object.create(obj);
296 | console.log(Object.getPrototypeOf(proto) === obj);`, 297 | output: `true` 298 | }, 299 | { 300 | name: 'setPrototypeOf', 301 | shortDesc: `установить прототип объекта.`, 302 | desc: `Внимание: этот метод ужасно медленный. Используйте с осторожностью, или замените на Object.create(). Задает прототип (то есть, внутреннее свойство [[Prototype]]) указанного объекта.`, 303 | example: `const dict = Object.setPrototypeOf({}, obj);
304 |
305 | console.log(dict);`, 306 | output: `Object {
307 |   a: 1,
308 |   b: 2,
309 |   c: 3
310 | }` 311 | }, 312 | { 313 | name: 'isPrototypeOf', 314 | shortDesc: `определить, входит ли объект в цепочку прототипов другого объекта.`, 315 | desc: `Возврашает логическое значение, указывающее, входит ли объект, вызываемый этим методом, в цепочку прототипов указанного объекта.`, 316 | example: `function Rect() {}
317 |
318 | var rect = new Rect();
319 |
320 | console.log(Rect.prototype.isPrototypeOf(rect));`, 321 | output: `true` 322 | } 323 | ] 324 | } 325 | } 326 | -------------------------------------------------------------------------------- /src/store/zh_cn.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: '创建一个新对象', 8 | desc: `创建一个带指定原型和属性的新对象。
9 |
10 | 初学者请注意! 一般来说创建一个对象会像例子的上方那样做,就是直接赋值给一个变量。`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: '创建一个对象的副本', 22 | desc: 23 | '从一个或多个源对象中复制它们的所有可枚举属性的值到一个目标对象中。并返回目标对象。', 24 | example: `const copy = Object.assign({}, obj);
25 | console.log(copy);`, 26 | output: `Object {
27 |   a: 1,
28 |   b: 2,
29 |   c: 3
30 | }` 31 | } 32 | ], 33 | createProp: [ 34 | { 35 | name: 'defineProperty', 36 | shortDesc: '一个新属性或修改现有的一个属性', 37 | desc: `向对象中添加一个带给定属性描述符的已命名的属性。
38 |
39 | 初学者请注意! 通常会使用小数点或方括号来创建一个新属性或修改现有属性。像这样:obj.a = 1obj[a] = 1。从技术上来说这不是一个内置的方法,所以没有包含进去。`, 40 | example: `Object.defineProperty(obj, 'd', {
41 |   enumerable: true,
42 |   configurable: true,
43 |   writable: true,
44 |   value: 4
45 | });
46 |
47 | console.log(obj.d);`, 48 | output: `4` 49 | }, 50 | { 51 | name: 'defineProperties', 52 | shortDesc: '一个或多个属性或修改现有的属性', 53 | desc: `向对象中添加一个或多个带给定属性描述符的属性。
54 |
55 | 初学者请注意! 通常会使用小数点或方括号来创建一个新属性或修改现有属性。像这样:obj.a = 1obj[a] = 1。从技术上来说这不是一个内置的方法,所以没有包含进去。`, 56 | example: `Object.defineProperties(obj, {
57 |   d: {
58 |     value: 4,
59 |     writable: true
60 |   },
61 |   e: {
62 |     value: 5,
63 |     writable: true
64 |   }
65 | });
66 |
67 | console.log(obj);`, 68 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 69 | } 70 | ], 71 | infoObj: [ 72 | { 73 | name: 'isExtensible', 74 | shortDesc: '是否可以添加更多的属性', 75 | desc: '检查是否允许扩展对象。', 76 | example: `console.log(Object.isExtensible(obj));
77 | Object.freeze(obj);
78 | console.log(Object.isExtensible(obj));`, 79 | output: `true
80 | false` 81 | }, 82 | { 83 | name: 'is', 84 | shortDesc: '两个引用是否指向同一对象', 85 | desc: 86 | '对比两个引用是否指向同一对象。NaN 与 NaN 比较会返回 true (与抽象等价比较和严格等价比较不同)(译者注:「抽象等价比较」就是带类型自动转换的比较,即“==”;「严格等价比较」则会比较两个变量的类型,即“===”)。这个有点奇怪,MDN 文档有点误导。', 87 | example: `let obj2 = {
88 |   a: 1,
89 |   b: 2,
90 |   c: 3
91 | };
92 |
93 | console.log(Object.is(obj, obj2));
94 | console.log(Object.is(obj, obj));`, 95 | output: `false
96 | true` 97 | }, 98 | { 99 | name: 'isFrozen', 100 | shortDesc: `对象及其属性是否不能被修改`, 101 | desc: '检查一个对象是否被冻结。', 102 | example: `console.log(Object.isFrozen(obj));
103 | Object.freeze(obj);
104 | console.log(Object.isFrozen(obj));`, 105 | output: `false
106 | true` 107 | }, 108 | { 109 | name: 'isSealed', 110 | shortDesc: `一个对象是否不能被修改(但属性可以)`, 111 | desc: 112 | '检查一个对象的属性的属性描述符是否不能被修改以及不能增加新的属性。', 113 | example: `Object.seal(obj);
114 |
115 | console.log(Object.isSealed(obj));`, 116 | output: `true` 117 | }, 118 | { 119 | name: 'isPrototypeOf', 120 | shortDesc: `对象是否在原型链里`, 121 | desc: `返回表示一个对象是否在另一指定对象的原型链上的布尔值。`, 122 | example: `function Rect() {}
123 |
124 | var rect = new Rect();
125 |
126 | console.log(Rect.prototype.isPrototypeOf(rect));`, 127 | output: `true`, 128 | useExample: 'newExample' 129 | } 130 | ], 131 | noChange: [ 132 | { 133 | name: 'seal', 134 | shortDesc: `让它不能添加或删除属性`, 135 | desc: '阻止删除一个对象的属性。现有的属性仍然能被修改。', 136 | example: `Object.seal(obj);
137 | delete obj.c;
138 |
139 | console.log(obj);`, 140 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 141 | }, 142 | { 143 | name: 'freeze', 144 | shortDesc: `让它不能添加、删除或修改属性`, 145 | desc: `冻结一个对象,使得它的属性不能被更改或删除。`, 146 | example: `Object.freeze(obj);
147 | obj.a = 10;
148 |
149 | console.log(obj.a);`, 150 | output: `1 //the value didn't update to 10` 151 | }, 152 | { 153 | name: 'preventExtensions', 154 | shortDesc: `让它不能添加属性`, 155 | desc: `阻止对象的扩展。仍然可以删除属性但不能添加属性。`, 156 | example: `Object.preventExtensions(obj);
157 | obj.d = 4;
158 |
159 | console.log(obj.d);`, 160 | output: `undefined` 161 | } 162 | ], 163 | createString: [ 164 | { 165 | name: 'toString', 166 | shortDesc: `表示这个对象的字符串`, 167 | desc: `toString() 方法返回表示这个对象的字符串。`, 168 | example: `console.log(obj.toString());
169 | console.log(obj.a.toString());`, 170 | output: `"[object Object]"
171 | "1"` 172 | }, 173 | { 174 | name: 'toLocaleString', 175 | shortDesc: `表示这个对象的本地化的字符串`, 176 | desc: `toLocaleString() 方法返回表示这个对象的字符串。这个方法可以根据按不同地域需要在派生对象中被重写。例如:您有一些因地域不同而不同的数据,如日期的方法,您可以得到不同的时间格式。`, 177 | example: `obj.d = new Date();
178 |
179 | console.log(obj.d);
180 | console.log(obj.d.toLocaleString());`, 181 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
182 | 12/29/2017, 8:57:35 PM` 183 | } 184 | ], 185 | infoProp: { 186 | details: [ 187 | { 188 | name: 'getOwnPropertyDescriptor', 189 | shortDesc: `关于属性的详细信息`, 190 | desc: '返回一个对象上已命名的属性的属性描述符。', 191 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
192 |
193 | console.log(o);`, 194 | output: `Object {
195 |   configurable: true,
196 |   enumerable: true,
197 |   value: 1,
198 |   writable: true
199 | }` 200 | }, 201 | { 202 | name: 'getOwnPropertyDescriptors', 203 | shortDesc: `一个对象上所有属性的详细信息`, 204 | desc: '返回一个包含对象上所有属性描述符的对象。', 205 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 206 | output: `Object {
207 |   a: Object {
208 |     configurable: true,
209 |     enumerable: true,
210 |     value: 1,
211 |     writable: true
212 |   },
213 |   b: Object {
214 |     configurable: true,
215 |     enumerable: true,
216 |     value: 2,
217 |     writable: true
218 |   },
219 |   c: Object {
220 |     configurable: true,
221 |     enumerable: true,
222 |     value: 3,
223 |     writable: true
224 |   },
225 | }` 226 | }, 227 | { 228 | name: 'propertyIsEnumerable', 229 | shortDesc: `一个属性是否可以在 for...in 循环中遍历`, 230 | desc: 231 | '返回表示内部的 ECMAScript [[Enumerable]] 属性是否已设置的布尔值。这个可以用来检查一个方法是内置的还是用户定义的,因为内置属性更偏向于不可被枚举。', 232 | example: `console.log(obj.propertyIsEnumerable('a'));
233 | console.log(Math.propertyIsEnumerable('random'));`, 234 | output: `true
235 | false` 236 | }, 237 | { 238 | name: 'hasOwnProperty', 239 | shortDesc: `一个属性是否直接存在于对象上`, 240 | desc: 241 | '返回表示对象是否包含指定属性并且直接存在于对象上而不是通过原型链继承得到。', 242 | example: `console.log(obj.hasOwnProperty('a'));
243 | delete obj.a;
244 | console.log(obj.hasOwnProperty('a'));`, 245 | output: `true
246 | false` 247 | } 248 | ], 249 | list: [ 250 | { 251 | name: 'keys', 252 | shortDesc: `键`, 253 | desc: `返回包含对象上所有可被循环的键的名称的数组,并按照它们被循环的顺序来排序。`, 254 | example: `console.log(Object.keys(obj));`, 255 | output: `["a", "b", "c"]` 256 | }, 257 | { 258 | name: 'values', 259 | shortDesc: `值`, 260 | desc: `返回包含对象上所有可被循环的值的数组,并按照它们被循环的顺序来排序。`, 261 | example: `console.log(Object.values(obj));`, 262 | output: `[1, 2, 3]` 263 | }, 264 | { 265 | name: 'entries', 266 | shortDesc: `键和值`, 267 | desc: `返回包含对象上所有可被循环的键值对的嵌套数组,并按照它们被循环的顺序来排序。`, 268 | example: `console.log(Object.entries(obj));`, 269 | output: `[["a", 1], ["b", 2], ["c", 3]]` 270 | }, 271 | { 272 | name: 'getOwnPropertyNames', 273 | shortDesc: `键,即使您不能循环它们`, 274 | desc: `返回包含对象上所有可枚举和不可枚举的属性的名称的数组,跟 Object.keys() 一样,可以得到对象的键,但 getOwnPropertyNames() 会包含不能通过循环来得到的属性。`, 275 | example: `Object.defineProperty(obj, 'a', {
276 |   enumerable: false
277 | });
278 |
279 | console.log(Object.keys(obj));
280 | console.log(Object.getOwnPropertyNames(obj));`, 281 | output: `["b", "c"]
282 | ["a", "b", "c"]` 283 | } 284 | ] 285 | }, 286 | prototype: [ 287 | { 288 | name: 'getPrototypeOf', 289 | shortDesc: `获取对象的原型`, 290 | desc: `返回指定对象的原型。(例如指定对象的内部 [[Prototype]] 属性的值)`, 291 | example: `const proto = Object.create(obj);
292 | console.log(Object.getPrototypeOf(proto) === obj);`, 293 | output: `true` 294 | }, 295 | { 296 | name: 'setPrototypeOf', 297 | shortDesc: `设置对象的原型`, 298 | desc: `警告:这个方法真的很慢。使用时要小心,或者用 Object.create() 带代替设置原型(例如内部的 [[Prototype]] 属性)。`, 299 | example: `const dict = Object.setPrototypeOf({}, obj);
300 |
301 | console.log(dict);`, 302 | output: `Object {
303 |   a: 1,
304 |   b: 2,
305 |   c: 3
306 | }` 307 | }, 308 | { 309 | name: 'isPrototypeOf', 310 | shortDesc: `知道一个对象是否在原型链上`, 311 | desc: `返回表示一个对象是否在另一指定对象的原型链上的布尔值。`, 312 | example: `function Rect() {}
313 |
314 | var rect = new Rect();
315 |
316 | console.log(Rect.prototype.isPrototypeOf(rect));`, 317 | output: `true` 318 | } 319 | ] 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /src/store/zh_hk.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | createObj: [ 5 | { 6 | name: 'create', 7 | shortDesc: '建立一個新的物件', 8 | desc: `建立一個帶有指定原型和屬性的新物件。
9 |
10 | 初學者請注意! 一般來說建立一個物件就像上方例子那樣直接賦予變數一個值 let obj = { a: 1 };。`, 11 | example: `const obj2 = Object.create(obj);
12 | console.log(obj2);`, 13 | output: `Object {
14 |   a: 1,
15 |   b: 2,
16 |   c: 3
17 | }` 18 | }, 19 | { 20 | name: 'assign', 21 | shortDesc: '建立一個物件複本', 22 | desc: `複製一個或多個物件自身所有可數的屬性到另一個目標物件。回傳的值為該目標物件。縱使在技術層面這不是一個物件的內置方法,當使用 ES6 時常見的做法是利用 展開運算子 ...`, 23 | example: `const copy = Object.assign({}, obj);
24 | console.log(copy);`, 25 | output: `Object {
26 |   a: 1,
27 |   b: 2,
28 |   c: 3
29 | }` 30 | } 31 | ], 32 | createProp: [ 33 | { 34 | name: 'defineProperty', 35 | shortDesc: '定義一個新屬性或修改一個現有的屬性', 36 | desc: `直接對一個物件定義一個屬性,或是修改現有的屬性。
37 |
38 | 初學者請注意! 常見的做法是使用小數點或方括號來定義一個新屬性或修改現有屬性。範例:obj.a = 1obj[a] = 1。從技術上來說這不是一個內置的函數,所以不包括在內。`, 39 | example: `Object.defineProperty(obj, 'd', {
40 |   enumerable: true,
41 |   configurable: true,
42 |   writable: true,
43 |   value: 4
44 | });
45 |
46 | console.log(obj.d);`, 47 | output: `4` 48 | }, 49 | { 50 | name: 'defineProperties', 51 | shortDesc: '定義一個或多個新屬性或修改一個或多個現有的屬性', 52 | desc: `直接對一個物件定義一個或多個屬性,或是修改現有的屬性。
53 |
54 | 初學者請注意! 常見的做法是使用小數點或方括號來定義一個新屬性或修改現有屬性。範例:obj.a = 1obj[a] = 1。從技術上來說這不是一個內置的函數,所以不包括在內。`, 55 | example: `Object.defineProperties(obj, {
56 |   d: {
57 |     value: 4,
58 |     writable: true
59 |   },
60 |   e: {
61 |     value: 5,
62 |     writable: true
63 |   }
64 | });
65 |
66 | console.log(obj);`, 67 | output: `{a: 1, b: 2, c: 3, d: 4, e: 5}` 68 | } 69 | ], 70 | infoObj: [ 71 | { 72 | name: 'isExtensible', 73 | shortDesc: '是否可以添加更多的屬性', 74 | desc: '檢查是否允許擴展物件。', 75 | example: `console.log(Object.isExtensible(obj));
76 | Object.freeze(obj);
77 | console.log(Object.isExtensible(obj));`, 78 | output: `true
79 | false` 80 | }, 81 | { 82 | name: 'is', 83 | shortDesc: '兩個引用是否指向同一物件', 84 | desc: `對比兩個引用是否指向同一物件。NaN 與 NaN 比較會返回 true (與抽像相等比較和嚴格相等比較不同)(譯者註:「抽像相等比較」就是將型別一致化後比較,即“==”;「嚴格相等比較」則會比較兩個值和型別,即“===”)。這個有點奇怪,MDN 文檔有點誤導。使用三個等號 === 來比較物件是否相同會更有效。`, 85 | example: `let obj2 = {
86 |   a: 1,
87 |   b: 2,
88 |   c: 3
89 | };
90 |
91 | console.log(Object.is(obj, obj2));
92 | console.log(Object.is(obj, obj));`, 93 | output: `false
94 | true` 95 | }, 96 | { 97 | name: 'isFrozen', 98 | shortDesc: `物件及其屬性是否不能被修改`, 99 | desc: '檢查一個物件是否被凍結。', 100 | example: `console.log(Object.isFrozen(obj));
101 | Object.freeze(obj);
102 | console.log(Object.isFrozen(obj));`, 103 | output: `false
104 | true` 105 | }, 106 | { 107 | name: 'isSealed', 108 | shortDesc: `一個物件是否不能被修改(但屬性可以)`, 109 | desc: '檢查一個物件及其屬性是否被封存。', 110 | example: `Object.seal(obj);
111 |
112 | console.log(Object.isSealed(obj));`, 113 | output: `true` 114 | }, 115 | { 116 | name: 'isPrototypeOf', 117 | shortDesc: `物件是否在原型鏈裡`, 118 | desc: `返回表示一個物件是否在另一指定物件的原型鏈上的布林值。`, 119 | example: `function Rect() {}
120 |
121 | var rect = new Rect();
122 |
123 | console.log(Rect.prototype.isPrototypeOf(rect));`, 124 | output: `true`, 125 | useExample: 'newExample' 126 | } 127 | ], 128 | noChange: [ 129 | { 130 | name: 'seal', 131 | shortDesc: `讓它不能添加或刪除屬性`, 132 | desc: '阻止刪除一個物件的屬性。現有的屬性仍然能被修改。', 133 | example: `Object.seal(obj);
134 | delete obj.c;
135 |
136 | console.log(obj);`, 137 | output: `{a: 1, b: 2, c: 3} // obj.c doesn't get deleted` 138 | }, 139 | { 140 | name: 'freeze', 141 | shortDesc: `讓它不能添加、刪除或修改屬性`, 142 | desc: `凍結一個物件,使得它的屬性不能被更改或刪除。`, 143 | example: `Object.freeze(obj);
144 | obj.a = 10;
145 |
146 | console.log(obj.a);`, 147 | output: `1 //the value didn't update to 10` 148 | }, 149 | { 150 | name: 'preventExtensions', 151 | shortDesc: `讓它不能添加屬性`, 152 | desc: `阻止物件的擴展。仍然可以刪除屬性但不能添加屬性。`, 153 | example: `Object.preventExtensions(obj);
154 | obj.d = 4;
155 |
156 | console.log(obj.d);`, 157 | output: `undefined` 158 | } 159 | ], 160 | createString: [ 161 | { 162 | name: 'toString', 163 | shortDesc: `表示這個物件的字符串`, 164 | desc: `toString() 方法返回表示這個物件的字符串。縱使這是一個內置的方法,更有效的方法是 JSON.stringify()`, 165 | example: `console.log(obj.toString());
166 | console.log(obj.a.toString());`, 167 | output: `"[object Object]"
168 | "1"` 169 | }, 170 | { 171 | name: 'toLocaleString', 172 | shortDesc: `表示這個物件的本地化的字符串`, 173 | desc: `toLocaleString() 方法返回表示這個對象的字符串。這個方法可以根據按不同地域需要在派生物件中被重寫。例如:您有一些因地域不同而不同的數據,如日期的方法,您可以得到不同的時間格式。`, 174 | example: `obj.d = new Date();
175 |
176 | console.log(obj.d);
177 | console.log(obj.d.toLocaleString());`, 178 | output: `Fri Dec 29 2017 20:57:35 GMT-0700 (MST)
179 | 12/29/2017, 8:57:35 PM` 180 | } 181 | ], 182 | infoProp: { 183 | details: [ 184 | { 185 | name: 'getOwnPropertyDescriptor', 186 | shortDesc: `關於屬性的詳細信息`, 187 | desc: '返回一個物件上已命名的屬性的屬性描述器。', 188 | example: `const o = Object.getOwnPropertyDescriptor(obj, 'a');
189 |
190 | console.log(o);`, 191 | output: `Object {
192 |   configurable: true,
193 |   enumerable: true,
194 |   value: 1,
195 |   writable: true
196 | }` 197 | }, 198 | { 199 | name: 'getOwnPropertyDescriptors', 200 | shortDesc: `一個物件上所有屬性的詳細信息`, 201 | desc: '返回一個包含物件上所有屬性描述器的物件。', 202 | example: `console.log(Object.getOwnPropertyDescriptors(obj))`, 203 | output: `Object {
204 |   a: Object {
205 |     configurable: true,
206 |     enumerable: true,
207 |     value: 1,
208 |     writable: true
209 |   },
210 |   b: Object {
211 |     configurable: true,
212 |     enumerable: true,
213 |     value: 2,
214 |     writable: true
215 |   },
216 |   c: Object {
217 |     configurable: true,
218 |     enumerable: true,
219 |     value: 3,
220 |     writable: true
221 |   },
222 | }` 223 | }, 224 | { 225 | name: 'propertyIsEnumerable', 226 | shortDesc: `一個屬性是否可以在 for...in 循環中遍歷`, 227 | desc: 228 | '返回表示內部的 ECMAScript [[Enumerable]] 屬性是否已設置的布林值。這個可以用來檢查一個方法是內置的還是用戶定義的,因為內置屬性更偏向於不可被枚舉。', 229 | example: `console.log(obj.propertyIsEnumerable('a'));
230 | console.log(Math.propertyIsEnumerable('random'));`, 231 | output: `true
232 | false` 233 | }, 234 | { 235 | name: 'hasOwnProperty', 236 | shortDesc: `一個屬性是否直接存在於物件上`, 237 | desc: 238 | '返回表示物件是否包含指定屬性並且直接存在於物件上而不是通過原型鏈繼承得到。', 239 | example: `console.log(obj.hasOwnProperty('a'));
240 | delete obj.a;
241 | console.log(obj.hasOwnProperty('a'));`, 242 | output: `true
243 | false` 244 | } 245 | ], 246 | list: [ 247 | { 248 | name: 'keys', 249 | shortDesc: `鍵`, 250 | desc: `返回包含物件上所有可被循環的鍵的名稱的數組,並按照它們被循環的順序來排序。`, 251 | example: `console.log(Object.keys(obj));`, 252 | output: `["a", "b", "c"]` 253 | }, 254 | { 255 | name: 'values', 256 | shortDesc: `值`, 257 | desc: `返回包含物件上所有可被循環的值的數組,並按照它們被循環的順序來排序。`, 258 | example: `console.log(Object.values(obj));`, 259 | output: `[1, 2, 3]` 260 | }, 261 | { 262 | name: 'entries', 263 | shortDesc: `鍵和值`, 264 | desc: `返回包含物件上所有可被循環的鍵值對的嵌套數組,並按照它們被循環的順序來排序。`, 265 | example: `console.log(Object.entries(obj));`, 266 | output: `[["a", 1], ["b", 2], ["c", 3]]` 267 | }, 268 | { 269 | name: 'getOwnPropertyNames', 270 | shortDesc: `鍵,即使您不能循環它們`, 271 | desc: `返回包含物件上所有可枚舉和不可枚舉的屬性的名稱的數組,跟 Object.keys() 一樣,可以得到物件的鍵,但 getOwnPropertyNames() 會包含不能通過循環來得到的屬性。`, 272 | example: `Object.defineProperty(obj, 'a', {
273 |   enumerable: false
274 | });
275 |
276 | console.log(Object.keys(obj));
277 | console.log(Object.getOwnPropertyNames(obj));`, 278 | output: `["b", "c"]
279 | ["a", "b", "c"]` 280 | } 281 | ] 282 | }, 283 | prototype: [ 284 | { 285 | name: 'getPrototypeOf', 286 | shortDesc: `獲取物件的原型`, 287 | desc: `返回指定物件的原型。 (例如指定物件的內部 [[Prototype]] 屬性的值)`, 288 | example: `const proto = Object.create(obj);
289 | console.log(Object.getPrototypeOf(proto) === obj);`, 290 | output: `true` 291 | }, 292 | { 293 | name: 'setPrototypeOf', 294 | shortDesc: `設置物件的原型`, 295 | desc: `警告:這個方法真的很慢。使用時要小心,或者用 Object.create() 來代替設置原型(例如內部的 [[Prototype]] 屬性)。`, 296 | example: `const dict = Object.setPrototypeOf({}, obj);
297 |
298 | console.log(dict);`, 299 | output: `Object {
300 |   a: 1,
301 |   b: 2,
302 |   c: 3
303 | }` 304 | }, 305 | { 306 | name: 'isPrototypeOf', 307 | shortDesc: `知道一個物件是否在原型鏈上`, 308 | desc: `返回表示一個物件是否在另一指定物件的原型鏈上的布林值。`, 309 | example: `function Rect() {}
310 |
311 | var rect = new Rect();
312 |
313 | console.log(Rect.prototype.isPrototypeOf(rect));`, 314 | output: `true` 315 | } 316 | ] 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const options = require('./src/options') 3 | 4 | const isObject = prop => 5 | !Array.isArray(prop) && prop !== null && typeof prop === 'object' 6 | 7 | test('en:', t => { 8 | let lang = 'en' 9 | 10 | let state = require('./src/store')[lang].state 11 | let questions = options(lang) 12 | 13 | const findQuestion = name => questions.find(obj => obj.name === name) 14 | const getOptions = name => state[name].map(s => s.shortDesc) 15 | 16 | test('initial', t => { 17 | t.plan(3) 18 | 19 | let question = findQuestion('init') 20 | 21 | t.deepEqual(question.name, 'init', 'name should be init ') 22 | 23 | t.deepEqual( 24 | question.message, 25 | 'I have an object, I would like to', 26 | 'displays appropriate message' 27 | ) 28 | 29 | t.deepEqual( 30 | question.choices, 31 | [ 32 | 'create an object', 33 | 'create properties', 34 | 'get information about an object', 35 | 'get information about properties', 36 | 'restrict changes to an object', 37 | 'create a string from an object', 38 | 'manage prototypes' 39 | ], 40 | 'displays the right choices' 41 | ) 42 | }) 43 | 44 | test('createObj', t => { 45 | t.plan(3) 46 | 47 | let name = 'createObj' 48 | 49 | let question = findQuestion(name) 50 | 51 | t.deepEqual(question.name, name, 'name should be ' + name) 52 | 53 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 54 | 55 | t.deepEqual( 56 | question.choices, 57 | getOptions(name), 58 | 'displays the right choices' 59 | ) 60 | }) 61 | 62 | test('createProp', t => { 63 | t.plan(3) 64 | 65 | let name = 'createProp' 66 | 67 | let question = findQuestion(name) 68 | 69 | t.deepEqual(question.name, name, 'name should be ' + name) 70 | 71 | t.deepEqual( 72 | question.message, 73 | 'I need to create', 74 | 'displays appropriate message' 75 | ) 76 | 77 | t.deepEqual( 78 | question.choices, 79 | getOptions(name), 80 | 'displays the right choices' 81 | ) 82 | }) 83 | 84 | test('infoObj', t => { 85 | t.plan(3) 86 | 87 | let name = 'infoObj' 88 | 89 | let question = findQuestion(name) 90 | 91 | t.deepEqual(question.name, name, 'name should be ' + name) 92 | 93 | t.deepEqual( 94 | question.message, 95 | 'I need to determine', 96 | 'displays appropriate message' 97 | ) 98 | 99 | t.deepEqual( 100 | question.choices, 101 | getOptions(name), 102 | 'displays the right choices' 103 | ) 104 | }) 105 | 106 | test('noChange', t => { 107 | t.plan(3) 108 | 109 | let name = 'noChange' 110 | 111 | let question = findQuestion(name) 112 | 113 | t.deepEqual(question.name, name, 'name should be ' + name) 114 | 115 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 116 | 117 | t.deepEqual( 118 | question.choices, 119 | getOptions(name), 120 | 'displays the right choices' 121 | ) 122 | }) 123 | 124 | test('createString', t => { 125 | t.plan(3) 126 | 127 | let name = 'createString' 128 | 129 | let question = findQuestion(name) 130 | 131 | t.deepEqual(question.name, name, 'name should be ' + name) 132 | 133 | t.deepEqual( 134 | question.message, 135 | 'I need to return a', 136 | 'displays appropriate message' 137 | ) 138 | 139 | t.deepEqual( 140 | question.choices, 141 | getOptions(name), 142 | 'displays the right choices' 143 | ) 144 | }) 145 | 146 | test('infoProp', t => { 147 | t.plan(3) 148 | 149 | let name = 'infoProp' 150 | 151 | let question = findQuestion(name) 152 | 153 | t.deepEqual(question.name, name, 'name should be ' + name) 154 | 155 | t.deepEqual( 156 | question.message, 157 | 'I need to get', 158 | 'displays appropriate message' 159 | ) 160 | 161 | t.deepEqual( 162 | question.choices, 163 | ['details about the property', 'a list of all of the keys and/or values'], 164 | 'displays the right choices' 165 | ) 166 | }) 167 | 168 | test('prototype', t => { 169 | t.plan(3) 170 | 171 | let name = 'prototype' 172 | 173 | let question = findQuestion(name) 174 | 175 | t.deepEqual(question.name, name, 'name should be ' + name) 176 | 177 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 178 | 179 | t.deepEqual( 180 | question.choices, 181 | getOptions(name), 182 | 'displays the right choices' 183 | ) 184 | }) 185 | 186 | t.end() 187 | }) 188 | 189 | test('others:', t => { 190 | Object.keys(require('./src/locale')).map(lang => { 191 | test(lang + ' works', t => { 192 | t.plan(2) 193 | 194 | let state = require('./src/store')[lang].state 195 | let questions = options(lang) 196 | 197 | t.equal(isObject(state), true) 198 | t.equal(Array.isArray(questions), true) 199 | }) 200 | }) 201 | t.end() 202 | }) 203 | --------------------------------------------------------------------------------