René's URL Explorer Experiment


Title: 【JavaScript】【学习心得】学习 JavaScript 第二十三天 · Issue #25 · paddingme/Learning-JavaScript · GitHub

Open Graph Title: 【JavaScript】【学习心得】学习 JavaScript 第二十三天 · Issue #25 · paddingme/Learning-JavaScript

X Title: 【JavaScript】【学习心得】学习 JavaScript 第二十三天 · Issue #25 · paddingme/Learning-JavaScript

Description: 昨天主要学习JavaScript的语法,先列出觉得重要的地方: ===(严格相等运算符)首先计算其操作数的值,再进行比较,比较过程中无任何类型转换,JS的对象比较是引用比较非值比较,对象只和对象本身相等,和任何其他对象不等; ==(相等运算符)null和undefined相等,其他不同的操作数比较时,有number转为number,有boolean也转为number,有string的转string再进行比较,看是否相等。对象互相不等,NaN互相不相等; JS依赖于全局变...

Open Graph Description: 昨天主要学习JavaScript的语法,先列出觉得重要的地方: ===(严格相等运算符)首先计算其操作数的值,再进行比较,比较过程中无任何类型转换,JS的对象比较是引用比较非值比较,对象只和对象本身相等,和任何其他对象不等; ==(相等运算符)null和undefined相等,其他不同的操作数比较时,有number转为number,有boolean也转为number,有string的转str...

X Description: 昨天主要学习JavaScript的语法,先列出觉得重要的地方: ===(严格相等运算符)首先计算其操作数的值,再进行比较,比较过程中无任何类型转换,JS的对象比较是引用比较非值比较,对象只和对象本身相等,和任何其他对象不等; ==(相等运算符)null和undefined相等,其他不同的操作数比较时,有number转为number,有boolean也转为number,有string的转str...

Opengraph URL: https://github.com/paddingme/Learning-JavaScript/issues/25

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"【JavaScript】【学习心得】学习 JavaScript 第二十三天","articleBody":"昨天主要学习JavaScript的语法,先列出觉得重要的地方:\n- ===(严格相等运算符)首先计算其操作数的值,再进行比较,比较过程中无任何类型转换,JS的对象比较是引用比较非值比较,对象只和对象本身相等,和任何其他对象不等;\n- ==(相等运算符)null和undefined相等,其他不同的操作数比较时,有number转为number,有boolean也转为number,有string的转string再进行比较,看是否相等。对象互相不等,NaN互相不相等;\n- JS依赖于全局变量进行连接,所有编译单元的所有级别对象都被抛入全局对象的公共命名空间中。当var语句被用在函数的内部时,他定义了这个函数的私有变量;\n- false,null,undefined,空字符串”,数字0,数字NaN都为假,其余皆为真;\n- 函数调用引发函数的执行,函数调用运算符是跟随在函数名后面的一对圆括号。\n- type of 运算符产生的值有‘number’ ‘string’ ‘boolean’ ‘undefined’ ‘function’和’object’(注意都是小写);而如果运算数是一个数组或null,结果是‘object’是不对的。\n\n第六条中typeof(null)或typeof(array)(array为一数组)为什么结果是'object'不对呢,查了查书,是因为:\n\n1.JavaScript本身对于数组和对象的区别很混乱,在区别数组和对象上没有一个很好的机制。typeof运算符报告数组的类型为‘object’没什么意义,可通过自定义is_array来判断是否为数组。\n2.typeof(null)很糟糕返回的不是null,我们知道JavaScript中有六种数据类型,分别为String,Number,Boolean,Null,Undefined,Object,(另外有些人把Function也作为一种数据类型,这里存在争议,有兴趣的同学可以参考\u003ca src=\"http://blog.csdn.net/aimingoo/article/details/6634977\"\u003e《再谈JavaScript的数据类型问题》\u003c/a\u003e)进一步理解。更好的检测null的方式应为my_value===null. 那么typeof如何区分对象和null呢,因为null值为假,所有对象值为真,所以可以有:\n\n``` js\nif(my_value\u0026\u0026typeof my_value==='object'){//my_value是一个对象或数组。}\n```\n\n好的,下面进入第三章对象的学习。\n\n---\n## 第三章  对象\n\nJavaScript中简单类型包括数字、字符串、布尔值、null值和undefined,其他所有的值都为对象(数组是对象,函数是对象,正则表达式是对象,对象当然也是对象)。String,Number,Boolean“貌似”对象,因为他们它们有自己的方法,但他们是不可变的。JavaScript中对象是可变的键控组合(keyed collections)(这句话如何理解?)。对象是属性的容器,其中每个属性都拥有名字和数值,属性的名字可是包括空字符串在内的任意字符串,而属性值可是除undefined值之外的任意值。JavaScript中的对象是无类别(class-free)的。即其对新属性的名字和值无约束。对象适合收集和管理数据。对象可以包含其他对象,所以他们可以容易地表示成树形或图形结构。JavaScript包括一个原型链特性,允许对象继承另一个对象的属性,正确的地使用它能减少对象初始化的时间和内存消耗。(后面讨论)\n### 3.1  对象字变量\n\n对象字面量提供了一种非常方便地创建新对象值的表示法。一个对象字面量就是包围在一对花括号中的零或多个“名/值”.对象字面量可出现在任何允许表达式出现的地方。\n\n``` js\nvar empty_object={};\n                var stooge={\n                \"first-name\"=\"Chouchou\",//(注意这里是逗号)\n                \"last-name=\"Shouchouchou\"//(注意这里没符号!)\n                                  }\n```\n\n属性名可以是包括空字符串在内的任何字符串。在对象字面量中,如果属性名是一个合法的JavaScript标识符且不是保留字,并不强制要求用引号括住属性名。所以用引号括住“fisrt-name”是必须的(因为含‘-’这个属性名不是合法的JS标识符,见上一章标识符定义“标示符有一个字母开头,其后可加一个或多个字母、数字或下划线,不允许使用保留字。”),而是否括住first_name才是可选的了。逗号用来分隔多个“名/值”对(原来JSON数据的渊源在这里)。\n\n属性的值可以从包括另一个对象字面量在内的任意表达式中获得。对象是可嵌套的。\n\n``` js\nvar flight={\n  airline=\"mh\",\n  number=370,\n  departure:{\n    IATA:\"KL\",\n    time:\"2014-03-08 00:25\",\n    city:\"Kuala Lumpu\"\n  },\n  arrival:{\n    IATA:\"CN\",\n    time:\"future\",\n    city:\"Beijing\"\n  }\n};\n```\n### 3.2   检索\n\n要检索对象中包含的值,可以采用在[]后缀中括住一个字符串表达式的方式。若字符串是一个常数且他是一个合法的JavaScript标识符而非保留字,那么也可以用.表示法代替,优先使用.表示法,因为更紧凑可读性更好。\n\n``` js\nstooge[\"first-name\"] //Chouchou\nflight.departure.city //\"Kuala Lumpu\"\n```\n\n若检索一个并不存在的成员元素的值,则返回undefined。\n\n||运算符可以用来填充默认值\n\n``` js\nvar status=flight.status||\"unkown\";\n```\n\n尝试检索一个undefined值将会导致TypeError异常。可通过\u0026\u0026避免错误。\n\n``` js\nflight.equipment//undefined\nflight.equipment.model//throw \"TypeError\"\nflight.equipment\u0026\u0026flight.equipment.model//undefined\n```\n### 3.3   更新\n\n对象中的值可以通过复制语句来更新,若属性名已经存在于对象中,那么该属性的值被替换,如果对象之前并未拥有这个属性名,则该属性会被扩充到该对象中。\n### 3.4   引用\n\n对象通过引用来传递。它们永远不会被拷贝。\n\n``` js\nvar x=chouchou;\nx.nickname='huang';\nvar nick=chouchou.nickname;\n//因为x和chouchou是指向同一个对象的引用,所以nick也为'huang'\nvar a={},b={},c={};\n//a,b,c每个都引用不同的空对象。\na=b=c={};\n//a,b,c都引用同一个空对象。\n```\n### 3.5    原型(prototype)\n\n每一个对象都连接到一个原型对象,并且它可以从中继承,所有通过对象字面量创建的对象都连接到Object.prototype这个JavaScript的标准对象。\n当创建一个新对象时,可选择某个对象作为它的原型。这个给Object增加一个beget方法,beget方法创建一个使用原对象作为其原型的新对象。(不是很明白,留坑)\n\n``` js\nif(typeof Object.beget !== 'function') {\n    Object.beget =function (o) {\n            var F=function () {};\n            F.prototype=o;\n            return new F(); \n    }\n}\nvar another_chouchou=Object.beget(chouchou);\n```\n\n原型连接在更新是不起作用的,当我们对某个对象做出改变时,不会触及到该对象的原型。原型连接只有在检索值时才被用到,如果我们尝试去获取对象的某个属性值,且该对象没有此属性名,则JavaScript试着从原型对象中获取属性值。如果那个原型对象也没有该属性,则从它的原型中寻找,依次类推,直到终点Object.prototype。如果想要的属性完全不在原型链中则返回undefined。这个过程称为\u003cstrong\u003e委托\u003c/strong\u003e\n\n原型关系是一种动态的关系。若我们添加一个新的属性到原型中,则该属性会立即对所有基于该原型创建的对象可见。\n\n``` js\nchouchou.profession=\"front-end develoer\";\nanother_chouchou.profession;//\"frond-end developer\"\n```\n### 3.6    反射\n\n检查对象并确定有什么属性很容易,只要试着去检索该属性并验证所取得的值。可用typeof,但是原型链中的任何属性也会产生一个值,例如\n\n``` js\ntypeof flight.toString //'function'\ntypeof flight.constructor //'function'\n```\n\n有两个方法去除这些不必要的属性。\n1.让你的程序检查并剔除函数值。一般来说,做反射的目标是数据。因此你应该意识到一些值可能会是函数。\n2.hasOwnProperty方法,如果对象拥有独立属性返回true,hasOwnProperty不会检查原型链。\n### 3.7    枚举\n\nfor in 语句可用来遍历一个对象中所有的属性名。该枚举过程将会列出所有的属性,包括函数和你可能不关心原型链中的属性。所以我们需要过滤,常用的过滤器是hasOwnProperty以及typeof来排除函数。属性名出现顺序不确定,要以确定的顺序应创建一个数组,在其中以正确的顺序包含属性名。\n\n``` js\nvar i;\nvar properties=['fistr-name','middle-name','last-name''profession'];\nfor(i = 0; i \u003c properties.length;i +=1 ){\n  document.writeln(properties[i]+':'+another.chouchou[propertites[i]]);\n}\n```\n### 3.8    删除\n\ndelete运算符可以用来删除对象的属性。它不会触及原型链中的任何对象。删除对象的属性可能让来自原型链中的属性浮现出来。\n\n``` js\nanother.chouchou.nickname //'me'\ndelete another.chouchou.nickname;\nanother.chouchou.nickname // 'huang'\n```\n### 3.9     减少全局变量污染\n\nJavaScript可以很随意的定义哪些可保存所有应用资源的全局变量。但全局变量减弱了程序的灵活性,应予以避免。最小化使用全局变量的方法是在你的应用中只创建一个全局变量。\n\n``` js\nvar MYAPP={};\n```\n\n该变量此时编程了你的应用的容器。\n\n``` js\nMYAPP.chouchou={\"first-name\":\"Chouchou\",\"last-name\":\"Shouchouchou\"};\nMYAPP.flight={airline=\"mh\",number=370,\n    departure:{\n      IATA:\"KL\",\n      time:\"2014-03-08 00:25\",\n      city:\"Kuala Lumpu\"\n    },\n    arrival:{\n      IATA:\"CN\",\n      time:\"future\",\n      city:\"Beijing\"\n    }\n};\n```\n\n只有把多个全局变量都整理在一个名称空间下,你讲显著降低与其他应用程序,组件或类库之间产生糟糕的相互影响的可能性。下一章将介绍闭包来有效减少全局污染。\n","author":{"url":"https://github.com/paddingme","@type":"Person","name":"paddingme"},"datePublished":"2014-12-09T16:40:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/25/Learning-JavaScript/issues/25"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6db4d816-c180-b632-ee77-94e535210dad
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE9E2:26FD39:6F52763:992B199:6A5EA974
html-safe-noncee7933191de874babd0d2fc98dc67fcc5101fa86a8de1053957df76cee4075ecd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUUyOjI2RkQzOTo2RjUyNzYzOjk5MkIxOTk6NkE1RUE5NzQiLCJ2aXNpdG9yX2lkIjoiMjA1Njc3MDIwODE2NjQ4ODQzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd9ece271b7c9ae374e14e68bc57d4c7deb8cded9715e8d594efbe74fa89dbe43
hovercard-subject-tagissue:51450030
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/paddingme/Learning-JavaScript/25/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fb14ac87fd5718777d908798698fc81d2f427720bff5cb41f18993689f2806ef/paddingme/Learning-JavaScript/issues/25
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fb14ac87fd5718777d908798698fc81d2f427720bff5cb41f18993689f2806ef/paddingme/Learning-JavaScript/issues/25
og:image:alt昨天主要学习JavaScript的语法,先列出觉得重要的地方: ===(严格相等运算符)首先计算其操作数的值,再进行比较,比较过程中无任何类型转换,JS的对象比较是引用比较非值比较,对象只和对象本身相等,和任何其他对象不等; ==(相等运算符)null和undefined相等,其他不同的操作数比较时,有number转为number,有boolean也转为number,有string的转str...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamepaddingme
hostnamegithub.com
expected-hostnamegithub.com
None7c7e31acb6a895494e518b880f5ccf39604f7fa9a8f2f3c64145efc3b776256d
turbo-cache-controlno-preview
go-importgithub.com/paddingme/Learning-JavaScript git https://github.com/paddingme/Learning-JavaScript.git
octolytics-dimension-user_id5771087
octolytics-dimension-user_loginpaddingme
octolytics-dimension-repository_id25473884
octolytics-dimension-repository_nwopaddingme/Learning-JavaScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id25473884
octolytics-dimension-repository_network_root_nwopaddingme/Learning-JavaScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2d2ac9bdd71d5f53f2b731c9330677e38624e301
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/paddingme/Learning-JavaScript/issues/25#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpaddingme%2FLearning-JavaScript%2Fissues%2F25
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpaddingme%2FLearning-JavaScript%2Fissues%2F25
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=paddingme%2FLearning-JavaScript
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/25
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/25
Reloadhttps://github.com/paddingme/Learning-JavaScript/issues/25
paddingme https://github.com/paddingme
Learning-JavaScripthttps://github.com/paddingme/Learning-JavaScript
Notifications https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Fork 13 https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Star 28 https://github.com/login?return_to=%2Fpaddingme%2FLearning-JavaScript
Code https://github.com/paddingme/Learning-JavaScript
Issues 30 https://github.com/paddingme/Learning-JavaScript/issues
Pull requests 0 https://github.com/paddingme/Learning-JavaScript/pulls
Actions https://github.com/paddingme/Learning-JavaScript/actions
Projects https://github.com/paddingme/Learning-JavaScript/projects
Wiki https://github.com/paddingme/Learning-JavaScript/wiki
Security and quality 0 https://github.com/paddingme/Learning-JavaScript/security
Insights https://github.com/paddingme/Learning-JavaScript/pulse
Code https://github.com/paddingme/Learning-JavaScript
Issues https://github.com/paddingme/Learning-JavaScript/issues
Pull requests https://github.com/paddingme/Learning-JavaScript/pulls
Actions https://github.com/paddingme/Learning-JavaScript/actions
Projects https://github.com/paddingme/Learning-JavaScript/projects
Wiki https://github.com/paddingme/Learning-JavaScript/wiki
Security and quality https://github.com/paddingme/Learning-JavaScript/security
Insights https://github.com/paddingme/Learning-JavaScript/pulse
【JavaScript】【学习心得】学习 JavaScript 第二十三天https://github.com/paddingme/Learning-JavaScript/issues/25#top
Mu-Help-Planhttps://github.com/paddingme/Learning-JavaScript/issues?q=state%3Aopen%20label%3A%22Mu-Help-Plan%22
https://github.com/paddingme
paddingmehttps://github.com/paddingme
on Dec 9, 2014https://github.com/paddingme/Learning-JavaScript/issues/25#issue-51450030
Mu-Help-Planhttps://github.com/paddingme/Learning-JavaScript/issues?q=state%3Aopen%20label%3A%22Mu-Help-Plan%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.