Created
January 23, 2017 02:35
-
-
Save anonymous/c50845062dee453ac8f405214b186fd4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/mowubenaji
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| var data = {'储存': ['32GB', '64GB'], | |
| '内存': ['2GB', '4GB'], | |
| '屏幕': ['5英寸', '4英寸']} | |
| console.log('处理结果:', handleAll(data)) | |
| // --- Object.create() 方法 (3) | |
| appData = Object.create(Object.prototype, { | |
| _data: { | |
| configurable: false, | |
| enumerable: false, | |
| writable: true, | |
| value: {} | |
| }, | |
| data: { | |
| configurable: false, | |
| enumerable: true, | |
| set: function (v) { | |
| this._data = v | |
| }, | |
| get: function () { | |
| return handleAll(this._data) | |
| } | |
| } | |
| }) | |
| appData.data = data | |
| console.log(appData.data) | |
| // --- 构建函数方法 (2) | |
| function Phones (data) { | |
| this.data = data | |
| } | |
| Phones.prototype = { | |
| format: function () { | |
| return handleAll(this.data) | |
| } | |
| } | |
| var phones = new Phones(data) | |
| console.log(phones.format()) | |
| // --- 原型链方法 (1) | |
| Object.prototype.format = function () { | |
| return handleAll(this) | |
| } | |
| console.log(data.format()) | |
| // --- 基础方法 (0) | |
| function handleAll (data) { | |
| var res = [] | |
| Object.keys(data).forEach(v => { | |
| res = pushData (completeData(data[v], v), res) | |
| }) | |
| return res | |
| } | |
| function pushData (arr, result) { | |
| if (result.length === 0) { | |
| return arr | |
| } | |
| var newResult = [] | |
| arr.forEach(v => { | |
| newResult = newResult.concat(plusData(result, v)) | |
| }) | |
| return newResult | |
| } | |
| function completeData (arr, string) { | |
| return arr.map(v => { | |
| return string + ': ' + v | |
| }) | |
| } | |
| function plusData (arr, string) { | |
| return arr.map(v => { | |
| return v + ', ' + string | |
| }) | |
| } | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var data = {'储存': ['32GB', '64GB'], | |
| '内存': ['2GB', '4GB'], | |
| '屏幕': ['5英寸', '4英寸']} | |
| console.log('处理结果:', handleAll(data)) | |
| // --- Object.create() 方法 (3) | |
| appData = Object.create(Object.prototype, { | |
| _data: { | |
| configurable: false, | |
| enumerable: false, | |
| writable: true, | |
| value: {} | |
| }, | |
| data: { | |
| configurable: false, | |
| enumerable: true, | |
| set: function (v) { | |
| this._data = v | |
| }, | |
| get: function () { | |
| return handleAll(this._data) | |
| } | |
| } | |
| }) | |
| appData.data = data | |
| console.log(appData.data) | |
| // --- 构建函数方法 (2) | |
| function Phones (data) { | |
| this.data = data | |
| } | |
| Phones.prototype = { | |
| format: function () { | |
| return handleAll(this.data) | |
| } | |
| } | |
| var phones = new Phones(data) | |
| console.log(phones.format()) | |
| // --- 原型链方法 (1) | |
| Object.prototype.format = function () { | |
| return handleAll(this) | |
| } | |
| console.log(data.format()) | |
| // --- 基础方法 (0) | |
| function handleAll (data) { | |
| var res = [] | |
| Object.keys(data).forEach(v => { | |
| res = pushData (completeData(data[v], v), res) | |
| }) | |
| return res | |
| } | |
| function pushData (arr, result) { | |
| if (result.length === 0) { | |
| return arr | |
| } | |
| var newResult = [] | |
| arr.forEach(v => { | |
| newResult = newResult.concat(plusData(result, v)) | |
| }) | |
| return newResult | |
| } | |
| function completeData (arr, string) { | |
| return arr.map(v => { | |
| return string + ': ' + v | |
| }) | |
| } | |
| function plusData (arr, string) { | |
| return arr.map(v => { | |
| return v + ', ' + string | |
| }) | |
| } | |
| </script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var data = {'储存': ['32GB', '64GB'], | |
| '内存': ['2GB', '4GB'], | |
| '屏幕': ['5英寸', '4英寸']} | |
| console.log('处理结果:', handleAll(data)) | |
| // --- Object.create() 方法 (3) | |
| appData = Object.create(Object.prototype, { | |
| _data: { | |
| configurable: false, | |
| enumerable: false, | |
| writable: true, | |
| value: {} | |
| }, | |
| data: { | |
| configurable: false, | |
| enumerable: true, | |
| set: function (v) { | |
| this._data = v | |
| }, | |
| get: function () { | |
| return handleAll(this._data) | |
| } | |
| } | |
| }) | |
| appData.data = data | |
| console.log(appData.data) | |
| // --- 构建函数方法 (2) | |
| function Phones (data) { | |
| this.data = data | |
| } | |
| Phones.prototype = { | |
| format: function () { | |
| return handleAll(this.data) | |
| } | |
| } | |
| var phones = new Phones(data) | |
| console.log(phones.format()) | |
| // --- 原型链方法 (1) | |
| Object.prototype.format = function () { | |
| return handleAll(this) | |
| } | |
| console.log(data.format()) | |
| // --- 基础方法 (0) | |
| function handleAll (data) { | |
| var res = [] | |
| Object.keys(data).forEach(v => { | |
| res = pushData (completeData(data[v], v), res) | |
| }) | |
| return res | |
| } | |
| function pushData (arr, result) { | |
| if (result.length === 0) { | |
| return arr | |
| } | |
| var newResult = [] | |
| arr.forEach(v => { | |
| newResult = newResult.concat(plusData(result, v)) | |
| }) | |
| return newResult | |
| } | |
| function completeData (arr, string) { | |
| return arr.map(v => { | |
| return string + ': ' + v | |
| }) | |
| } | |
| function plusData (arr, string) { | |
| return arr.map(v => { | |
| return v + ', ' + string | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment