推荐的书:Soft Skills: A Developer’s Life Manual by John Sonmez
The following is a link to a GitHub.com repository we are using for this course:
https://github.com/jhu-ep-coursera/fullstack-course4
It contains:
其中,Browser Sync用途:在本地编辑代码然后保存后,可以即时显示在浏览器中
安装方法:
要先安装Node.js,然后打开命令行或者Node.js command prompt:
// 配置国内的npm源:
npm config set registry https://registry.npm.taobao.org
// 配置后可通过下面方式来验证是否成功
npm config get registry
// 安装
npm install -g browser-sync
// 验证是否安装成功
browser-sync --version
使用:在对应的文件夹中输入命令(在命令行)
browser-sync start --server --directory --files "*"
html5 standards: https://www.w3.org/TR/html52/
caniuse.com : 查某项功能有哪些浏览器支持
validator.w3.org : 验证html代码的语法是否正确
等号前后可以有空格
The head tag contains items that describe the main content of the page. Things like what character coding should the browser use for the main content. It can contain authors description of the page, page title, and whatever other external resources are needed to render the page properly, among other things. ==The point is it contains some metadata about the main content. ==
The term content model refers to the full behavior the browser applies to the elements belonging to that content model, and to the nesting rules of those elements. In other words, which elements are allowed to be nested inside which other elements. Prior to HTML5 specification, HTML elements were either block level or inline elements. HTML5 split these two content models into seven models.
The div element stands for division, and the span element stands for span. The div element is your most generic block-level element, and the span is your super generic, inline element.New HTML5 Elements
The most interesting new HTML5 elements are:
New semantic elements like
New attributes of form elements like number, date, time, calendar, and range.
New graphic elements: .
New multimedia elements: .
Non-breaking Space
A common character entity used in HTML is the non-breaking space:  
;
A non-breaking space is a space that will not break into a new line.
Two words separated by a non-breaking space will stick together (not break into a new line). This is handy when breaking the words might be disruptive.
Examples:
In HTML, links are defined with the tag:
href: hypertext reference
Link Titles:
The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element.
In HTML, images are defined with the tag. It is an inline element.
The tag is empty, it contains attributes only, and does not have a closing tag.
The alt Attribute
The alt attribute provides an alternate text for an image, if the user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
So one thing to notice here is that out of all the selectors, the element selector, the class selector and the id selector, the id is the least reusable one. That makes sense, right? Since by HTML rules, a particular id attribute value can only appear once in a document.
select elements with both class ‘highlight’ and class ‘mainpoing’
inline styling: use style as an attribute; not recommended; can be used for quick testing
when targeting the same elements and having conflicts&
when targeting the same elements but for different properties
The basic idea is that you have the document object model tree. And if you specify some CSS property on some element, all the children and grandchildren and so on and so on of that element will also inherit that property without you having to specify the property for each and every element.
字体颜色可以通过6位16进制数字来表示,前两位、中间两位、最后两位分别表示红绿蓝(RGB)的颜色深度
2em表示再将当前字体大小增大一倍
In HTML every element is considered a box.
The box model refers to the components that make up an HTML box as well as the rules that govern how these box components affect the layout as well as how width and height of the box are calculated.
margin不算是box的一部分
设置width时:默认为指定content的宽度,不包括padding、border、margin等
通过设置box-sizing: border-box;
,可以将宽度指定为content加padding加border的宽度(recommended)
当文本内容超出给定的宽、高限制时,使用overflow来调节
this way is not recommended nowadays
告诉浏览器不要对页面进行缩放,按照设备原来的宽度来显示页面就行
Lecture 25 introduce how to get started with bootstrap
用于制作模板:
https://balsamiq.com/
tag中:
# 以上代码告诉IE浏览器,IE8/9及以后的版本都会以最高版本IE来渲染页面。
# 这行代码一般要放在靠前的位置
让browser-sync关注当前目录及子目录:
** HTML
HTML Tag:
从bootstrap官网复制的模板 - 用于小屏幕时右上角的菜单按键:
为none时,对应的element在页面中不显示
用来设定在大于一定宽度时,不显示
使用bootstrap提供的图标:
这些icon属于font-icon,所以可以通过font-size来调整大小
用这个网站来得到指定大小的图片来占位置:
使用地图:
将下面的链接放在元素的href属性中:
embed map放在html中的对应位置
HTML
Tag:
The
tag defines a thematic break in an HTML page (e.g. a shift of topic).
The
element is used to separate content (or define a change) in an HTML page.
The line-height property specifies the height of a line:
return后面也可以不跟任何值,来表明当前函数结束
All arguments defined in a JavaScript function are optional. You can call that same compare function without any arguments at all, and it all will be perfectly legal.
What this means is that it does not matter where a particular function is executed. What matters as far as resolving scope of a variable is concerned is where that function is physically defined. Function B is physically defined inside the global scope. Therefore a reference of x inside function B Is going to look inside function B first. If it doesn’t find it it’s going to use its outer reference to look for it there and its outer reference is the global scope.
**String concatenation: **
其中,第二段代码出现了type coercion
And type coercion just means that the language converts something for you from one type to another type automatically on the fly.
Strict Equality
Strict equality operator (===
) differs from regular equality operator (==
) in that it checks if both values on its right and left are of the same type first. If they are not, it doesn’t try to coerce them to be the same value and just returns false.
** What is true / false:**
快速判断:
As a side point, even though semicolons at the end of statements are optional in JavaScript, it is pretty much an accepted best practice to always put them there.
For loop
a || b
:if (a) return a; else if (b) return b
Functions in JavaScript are objects. They’re regular objects that have some special properties to them. So since they’re regular objects, I should be able to set properties on them just like I set properties on the other object.
当传递给函数的参数为primitive type时:
当传递给函数的参数为object时:
this指向当前对象
**Function Constructors: **
And when we see the new keyword, the this variable inside of that object is now referring to the actual object and not to the outside window or outside global object. So this in fact works exactly like function constructors in terms of the new keyword. Right, even though the new keyword here is kind of implicit, well everything’s here implicit, since this is an object literal.
So because of dynamic typing, in JavaScript I’m able to store different types of objects in the same array, which is not true of most languages.
Short hand array creation:
Now what’s interesting about arrays in JavaScript is that they can even be sparse.
遍历Object:
遍历array:
arrays are just objects in JavaScript, this for loop will loop over properties, even over properties that really have nothing to do with the core data that we want to loop over.
So how then can it possibly know what the multiplier variable is? Because at the time that this is executing the makeMultiplier function is no longer in the execution stack. It’s done. It returned whatever we needed to return, and is no longer functioning. It’s done. It’s part of the execution stack. Well, the reason this still works is because of JavaScript closures. Since a function like this returned from inside of this function JavaScript preserves its outer lexical environment memory space for this function, so this function can go ahead and produce what it needs to produce. So the multiplier is something that’s still sitting in memory in lexical outside scope of this function. So even when we call doubleALL it will go ahead and execute this function. It will create its own execution environment. It will go ahead and look for the multiplier variable in its own execution environment. It will not find it and it will then try to look for for this variable in its outer lexical environment, and the outer lexical environment memory space will still remain even though the makeMultiplier function no longer exists. That’s how we basically are able to trap or to close in whatever variables and whatever memory space is sitting outside of the lexical environment of this return function, and that’s how closures work.
this is something that you could do in order to separate kind of your name spaces, separate your functionality into separate files and also into separate name spaces, so you don’t step one up on the other.
the document object contains our entire HTML page
document.getElementById("title");
会在被引用时就运行其中的js代码,所以要取得页面内容的话,一般将
放在最后:
So document is actually an instance of HTMLDocument:
注意:包含这个函数的script.js只能在的最后引用,否则会报错(找不到对应的element)
在这两种方法中,sayHello()函数中的this变量指向当前的element(在当前例子中就是)
Event相关文档:
https://developer.mozilla.org/en-US/docs/Web/API/Event
And if you just come over to me and give me this URI /official_web_site/index.html, I will not be able to get that resource because I won’t know where to go to get it. Once you take me to where to get it, if you take me to coursera.org, and I start from the root of coursera.org, and I could start searching /official_web_site/index.html, then I’m able to get it. But URI by itself doesn’t necessarily tell us how to get that resource.
This command is only issued once the browser actually connects to the server. So we’re already connected to coursera.org or to mysite.org. And now that we’ve connected and established a connection to that particular website, now we are asking for a URI within the context of that website.
And what it does is it checks what type of object is available to us. Now the very first if right here is the most most important one because this is the most current object or the most current version of the Ajax object there is. The rest of them are kind of for the old browser, so window.ActiveXObject that’s something old Internet Explorer browsers used and really is not used anymore and if you wanted to you could really probably take out this whole thing out of here. Very few Microsoft Explorer browsers out there that are that old. And the last thing is just, just in case there’s a browser out there that’s going to access this that does not support Ajax at all, which means this object will not be available. Neither will this object be available. We’re going to go ahead and pop up a message, an alert here on window object which is what this global is pointing to. And we’ll just say Ajax is not supported, not necessarily the best message to return but it’s good enough. It’s probably never going to happen, anyway. And instead of the object, we’ll just return null. So point is, this is that object that we could use to make a request. And we’re creating here a new XML HTTP request object. ==And this is what we’re going to use in our main function that we’re going to write in a minute, we’re going to see in a minute. ==
这里的request其实包含的是response的内容
JSON is just a string. So it can be used in Javascript like this:
利用javascript,当点出上面的菜单,然后点其他地方时,自动将菜单缩回去:
第五行window.innerWidth
: it’s the width of the browser itself not the entire screen of the monitor
This main content of the front page to load this whole content dynamically. Now first of all, why do we want to do that? The reason we want to do it is because we’re trying to move towards what’s called an SPA, or SPA and stands for single page application. So a single page web application.
从http://www.ajaxload.info/ 下载加载图片时的占位图:
Chrome浏览器 - 右键 - 检查 - Network - XHR
XHR: XMLHttpRequest, that’s the Ajax request