From c639b0c4154801136cad04310a75fd6d1b6c9270 Mon Sep 17 00:00:00 2001 From: "H.C. Chen" Date: Wed, 11 Jan 2017 14:23:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=80=99=E4=B8=80=E6=AE=B5=E8=A9=B1?= =?UTF-8?q?=E7=9A=84=E6=84=8F=E6=80=9D=E8=AD=AF=E5=8F=8D=E4=BA=86,?= =?UTF-8?q?=E8=AB=8B=E5=8F=83=E8=80=83=E6=96=B0=E8=AD=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/zhtw/object/prototype.md | 5 ++--- package.json | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/doc/zhtw/object/prototype.md b/doc/zhtw/object/prototype.md index 83ad784a..8ab018e7 100644 --- a/doc/zhtw/object/prototype.md +++ b/doc/zhtw/object/prototype.md @@ -1,9 +1,8 @@ ## Prototype -JavaScript 不包含傳統繼承的模型,它使用的是*原型*模型。 +JavaScript 不包含傳統的「類」繼承的模型,它使用的是「原型」模型。 -儘管常常有人提及 JavaScript 的缺點,但基於原型的繼承模型比傳統繼承更強大。 -實現傳統的類繼承模型是很簡單。但是在 JavaScript 中實現原型的繼承模型則要困難很多。 +儘管這常被認為是 JavaScript 的缺點,但「原型繼承模型」其實比「類繼承模型」更強大。在「原型繼承模型」上實現傳統的「類繼承模型」是小事一件,但反過來要在只有「類繼承模型」的地方弄出「原型繼承模型」則要困難很多。 由於 JavaScript 是唯一一個被廣泛使用的基於原型繼承的語言,所以我們必須要花時間來理解這兩者的不同。 diff --git a/package.json b/package.json index a9662f9f..1318a3a7 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "dependencies": { "fomatto": "0.5.0", "forever": "0.10.8", - "jade": "0.35.0", - "neko": "1.1.2", - "marked": "~0.2.9", - "lodash": "~2.2.1" + "jade": "^0.35.0", + "lodash": "^2.4.2", + "marked": "^0.2.10", + "neko": "1.1.2" } } From 781a8f4a920ccefb979e6fb67b218d12d0925f7c Mon Sep 17 00:00:00 2001 From: "H.C. Chen" Date: Mon, 16 Jan 2017 13:55:06 +0800 Subject: [PATCH 2/3] x1 yoga --- doc/en/object/forinloop.md | 6 ++ doc/en/object/general.md | 1 + log.txt | 122 +++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 log.txt diff --git a/doc/en/object/forinloop.md b/doc/en/object/forinloop.md index 28d586c4..1ae30076 100644 --- a/doc/en/object/forinloop.md +++ b/doc/en/object/forinloop.md @@ -54,6 +54,12 @@ libraries like [Prototype][1], which does not yet take advantage of new ECMAScri When this framework is included, `for in` loops that do not use `hasOwnProperty` are guaranteed to break. +> Tried in jeforth +> js> [].length . \ ==> 0 OK +> js> [] obj>keys . \ ==> "" OK +> js> [].hasOwnProperty("length") \ ==> true (boolean) +> So 'length' is a non-enumerable property of an array. + ### In Conclusion It is recommended to **always** use `hasOwnProperty` in ECMAScript 3 or lower, as well as diff --git a/doc/en/object/general.md b/doc/en/object/general.md index 5ee2e0de..99c7a957 100644 --- a/doc/en/object/general.md +++ b/doc/en/object/general.md @@ -22,6 +22,7 @@ as objects too. 2..toString(); // the second point is correctly recognized 2 .toString(); // note the space left of the dot (2).toString(); // 2 is evaluated first + 2["toString"](); // alternative notation avoids using the dot ### Objects as a Data Type diff --git a/log.txt b/log.txt new file mode 100644 index 00000000..d8f89997 --- /dev/null +++ b/log.txt @@ -0,0 +1,122 @@ + +[x] The "javascript garden" project needs to be built before browsing according to CONTRIBUTING.md + So I run the build command line: + Microsoft Windows [Version 10.0.14393] + (c) 2016 Microsoft Corporation. All rights reserved. + + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm run build + + > javascript-garden@0.0.0 build c:\Users\hcche\Documents\GitHub\JavaScript-Garden + > node build.js + + module.js:327 + throw err; + ^ + + Error: Cannot find module 'lodash' + at Function.Module._resolveFilename (module.js:325:15) + at Function.Module._load (module.js:276:25) + at Module.require (module.js:353:17) + at require (internal/module.js:12:17) + at Object. (c:\Users\hcche\Documents\GitHub\JavaScript-Garden\build.js:2:9) + at Module._compile (module.js:409:26) + at Object.Module._extensions..js (module.js:416:10) + at Module.load (module.js:343:32) + at Function.Module._load (module.js:300:12) + at Function.Module.runMain (module.js:441:10) + + npm ERR! Windows_NT 10.0.14393 + npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run + " "build" + npm ERR! node v4.4.3 + npm ERR! npm v2.15.1 + npm ERR! code ELIFECYCLE + npm ERR! javascript-garden@0.0.0 build: `node build.js` + npm ERR! Exit status 1 + npm ERR! + npm ERR! Failed at the javascript-garden@0.0.0 build script 'node build.js'. + npm ERR! This is most likely a problem with the javascript-garden package, + npm ERR! not with npm itself. + npm ERR! Tell the author that this fails on your system: + npm ERR! node build.js + npm ERR! You can get information on how to open an issue for this project with: + npm ERR! npm bugs javascript-garden + npm ERR! Or if that isn't available, you can get their info via: + npm ERR! + npm ERR! npm owner ls javascript-garden + npm ERR! There is likely additional logging output above. + + npm ERR! Please include the following file with any support request: + npm ERR! c:\Users\hcche\Documents\GitHub\JavaScript-Garden\npm-debug.log + + c:\Users\hcche\Documents\GitHub\JavaScript-Garden> + [ ] check the error, RI: a module "lodash" is missing. So I studied and found how to install + that module: http://www.w3cplus.com/javascript/lodash-intro.html ( See my Ynote and Evernote ) + --> install lodash: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm install --save lodash + npm WARN package.json javascript-garden@0.0.0 No repository field. + npm WARN package.json javascript-garden@0.0.0 No license field. + lodash@2.2.1 node_modules\lodash + --> ok? Try building j/g again: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm run build + > javascript-garden@0.0.0 build c:\Users\hcche\Documents\GitHub\JavaScript-Garden + > node build.js + module.js:327 + throw err; + ^ + Error: Cannot find module 'jade' + at Function.Module._resolveFilename (module.js:325:15) + at Function.Module._load (module.js:276:25) + at Module.require (module.js:353:17) + at require (internal/module.js:12:17) + at Object. (c:\Users\hcche\Documents\GitHub\JavaScript-Garden\build.js:3:12) + at Module._compile (module.js:409:26) + at Object.Module._extensions..js (module.js:416:10) + at Module.load (module.js:343:32) + at Function.Module._load (module.js:300:12) + at Function.Module.runMain (module.js:441:10) + --> so, again, missing 'jade' module. + --> install jade: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm install --save jade + --> try again: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm run build + Error: Cannot find module 'marked' + at Function.Module._resolveFilename (module.js:325:15) + at Function.Module._load (module.js:276:25) + --> so, again, missing 'marked' module. + --> install marked: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm install --save marked + --> try again: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm run build + + > javascript-garden@0.0.0 build c:\Users\hcche\Documents\GitHub\JavaScript-Garden + > node build.js + + c:\Users\hcche\Documents\GitHub\JavaScript-Garden> + ==> OK now, Bingo! + Taget directory c:\Users\hcche\Documents\GitHub\JavaScript-Garden\site + was very empty but now is full of different languages and index.html appears. +[x] Modify the 'prototype.md' to be : + JavaScript 不包含傳統的「類」繼承的模型,它使用的是「原型」模型。 + 儘管這常被認為是 JavaScript 的缺點,但「原型繼承模型」其實比「類繼承模型」更強大。 + 在「原型繼承模型」上實現傳統的「類繼承模型」是小事一件,但反過來要在只有「類繼承模 + 型」的地方弄出「原型繼承模型」則要困難很多。 + --> submit --> push to my fork. + [x] How to make a PR (Pull request)? + --> Found a [New pull request] button on my repo's home page. --> click it, switched + to a page "Comparing changes" and it says : Choose two branches to see what’s changed or + to start a new pull request. If you need to, you can also compare across forks. --> so + I check the difference and it's fine. The page also says : "Able to merge. These branches + can be automatically merged." so I am about to proceed. + --> And, for the safe, I rebuilt again: + c:\Users\hcche\Documents\GitHub\JavaScript-Garden>npm run build + > javascript-garden@0.0.0 build c:\Users\hcche\Documents\GitHub\JavaScript-Garden + > node build.js + and then view the changes on my local browser to make sure it works fine: + file:///C:/Users/hcche/Documents/GitHub/JavaScript-Garden/site/zhtw/index.html#object.prototype + --> OK! + --> There's a button "[Create pull request] Discuss and review the changes in this comparison + with others." and I click it . . . + --> follow the process to provide some descriptions and then submit and DONE! + The pull request is really went to the original repo BonsaiDen/JavaScript-Garden + \ No newline at end of file From 4e8208837b2460171b46abea0e077b8ef4be20ee Mon Sep 17 00:00:00 2001 From: "H.C. Chen" Date: Mon, 16 Jan 2017 18:38:35 +0800 Subject: [PATCH 3/3] for in loop length' is a non-enumerable property of an array. --- doc/en/object/forinloop.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/en/object/forinloop.md b/doc/en/object/forinloop.md index 1ae30076..4b0aa053 100644 --- a/doc/en/object/forinloop.md +++ b/doc/en/object/forinloop.md @@ -47,6 +47,12 @@ When `hasOwnProperty` is left out, the code is prone to errors in cases where the native prototypes - e.g. `Object.prototype` - have been extended. +> Tried in jeforth +> js> [].length . \ ==> 0 OK. +> js> [] obj>keys . \ ==> "" OK. +> js> [].hasOwnProperty("length") \ ==> true (boolean). +> So 'length' is a non-enumerable property of an array. + In newer versions of ECMAScript, non-enumerable properties can be defined with `Object.defineProperty`, reducing the risk of iterating over properties without using `hasOwnProperty`. Nonetheless, care must be taken when using older @@ -54,12 +60,6 @@ libraries like [Prototype][1], which does not yet take advantage of new ECMAScri When this framework is included, `for in` loops that do not use `hasOwnProperty` are guaranteed to break. -> Tried in jeforth -> js> [].length . \ ==> 0 OK -> js> [] obj>keys . \ ==> "" OK -> js> [].hasOwnProperty("length") \ ==> true (boolean) -> So 'length' is a non-enumerable property of an array. - ### In Conclusion It is recommended to **always** use `hasOwnProperty` in ECMAScript 3 or lower, as well as