javascript 高级程序设计(第三版)读后归纳
转化函数
toString()
Number()
toFixed() 按照指定的小数位返回数值的字符串表示 如:var num = 10; alert(num.toFixed(2)) //"10.00"
访问字符串特定字符的方法
charAt()单字符字符串方式返回
charCodeAt()返回字符编码
length()字符串长度
字符串操作方法
concat()字符串连接,等同于+号(不影响原字符串)
基于子字符串创建新字符串的方法,返回子字符串(不影响原字符串)
slice() substring() 第一个参数代表指定字符串开始的位置,第二个参数代表子字符串最后一个字符后面的位置(没传第二个参数代表将字符串长度作为结束位置)
substr() 第一个参数代表指定字符串开始的位置,第二个参数代表字符个数(没传第二个参数代表将字符串长度作为结束位置)
字符串位置方法
indexOf() lastIndexOf()
trim() 创建一个字符串副本,删除前置以及后缀的所有空格,然后返回结果
trimLeft()删除字符串开头空格 trimRight()删除字符串末尾空格
字符串大小写转换
toUpperCase() 转换成大写 toLocalUpperCase() 针对地区转换大写
toLowerCase() 转换成小写 toLocalLowerCase() 针对地区转换小写
字符串的模式匹配
match() 只接受一个参数(正则表达式或者RegExp对象)本质上与调用RegExp的exec()方法相同
search()只接受一个参数(正则表达式或者RegExp对象)方法返回第一个匹配的索引,没有匹配项则返回-1
replace() 字符串替换
split()用指定分隔符将字符串分割成多个子字符串,并将结果放在一个数组中(分隔符可以是字符串也可以是RegExp对象),第二个参数可以指定数组大小
localeCompare() 字母表中的排列比较
fromCharCode()接收一或者多个字符编码,然后将它们转换成一个字符串,与charCodeAt()相反 String.fromCharCode[104,101,108,108,111] //"hello"
Global对象的方法
isNan() isFinite() parseInt() parseFloat()
URI编码方法
encodeURI()主要用于整个URL,不会对URL的特殊字符进行编码
edcodeURIComponent() 主要对于URL中的某一段进行编码,会对任何非标准字符进行编码
eval() 把传人的参数当做js语句执行
math对象
求最大最小值
min() max() 例如:找数字的最大值 var values = [1,2,3,4,5,6]; var max = Math.max.apply(Math,values);
舍入方法
Math.ceil()向上取整 Math.floor() 向下取整 Math.round() 四舍五入
Math.random() 返回0和1之前的随机数,不包括0和1 (p136)
从某个整数范围内随机选择一个值->公式: 值 = Math.floor(Math.random() * 可能的值的总数 + 第一个可能的值)
Math.abs(num) 返回num的绝对值
面向对象
属性类型
1.数据属性(configurable、enumerable、writable、value)
修改属性默认的特性用Object.defineProperty()方法
方法接收三个参数:属性所在的对象,属性名字和一个描述符对象,描述符(descriptor)对象的属性必须是
configurable、enumerable、writable、value。设置其中的一个或多个值,可以修改对应的特
性值。如:
var person = {};
Object.definProperty(person, "name",{
configurable: false,
value:"nicholas"
});
alert(person.name); // "nicholas"
delete person.name;
alert(person.name); // "nicholas"
2.访问器属性(configurable、enumerable、get、set)
访问器属性不包含数据值,包含getter和setter函数
定义多个属性
读取属性的方法(Object.getOwnProtertyDescriptor() 取得给定属性的描述符)
1.工厂模式
function createPerson(name, age, job){var o = new Object();o.name = name;o.age = age;o.job = job;o.sayName = function () {alert(this.name);}return o;
}
var person1 = new createPerson("nicholas", 29, "software");
var person2 = new createPerson("greg", 30, "doctor");
2.构造函数模式
function Person(name, age, job){this.name = name;this.age = age;this.job = job;this.sayName = function () {alert(this.name);}
}
var person1 = new Person("nicholas", 29, "software");
var person2 = new Person("greg", 30, "doctor");3.原型模式
function Person() {
}
Person.prototype.name = "nicholas";
Person.prototype.age = 29;
Person.prototype.job = "software";
Person.prototype.sayName = function () {
alert(this.name);
}
var person1 = new Person();实例中的指针仅指向原型,而不指向构造函数(重要,记住)。 delete操作符可以完全删除实例属性,从而让我们重新访问原型属性。
hasOwnProperty()检测属性存在实例中还是原型中,存在实例中返回true。
function Person() {
}
Person.prototype = {
name : "nicholas",
age : 29,
job : "software",
sayName : function () {
alert(this.name);
}
}
var person1 = new Person();
this.name = name;
this.age = age;
this.job = job;
}
Person.prototype.sayName = function () {
alert(this.name);
}
var person1 = new Person("greg", 30, "doctor");
this.name = name;
this.age = age;
this.job = job;
this.friends = ["shery", "court"]
}
Person.prototype = {
constructor : Person,
sayName = function(){
alert(this.name);
}
}
var person1 = new Person("nicholas", 29, "software");
var person2 = new Person("greg", 30, "doctor")
this.name = name;
this.age = age;
this.job = job;
if(typeof this.sayName != "function"){
Person.prototype.sayName = function () {
alert(this.name);
}
}
}
var person1 = new Person("nicholas", 29, "software");
function SpecialArray(){
var values = new Array();
values.push.apply(values, arguments);
values.toPipedString = function () {
return this.join('|');
}
return values;
}
var colors = new SpecialArray("red", "blue", "green");
alert(colors.toPipedString()); // "red|blue|green"
7.稳妥构造函数
function Person(name, age, job) {
var o = new Object();
o.sayName = function () {
alert(name);
}
return o;
}
1.借用构造函数(经典继承) (传递参数)
function SuperType(name) {
this.name = name;
}
function SubType() {
SuperType.call(this,"nicholas");
this.age = 29;
}
var instance = new SubType();
alert(instance.name);
alert(instance.age);
2.组合继承(伪经典继承)最常用的继承模式
function SuperType(name) {
this.name = name;
this.colors = ["red", "blue", "green"];
}
SuperType.prototype.sayName = function () {
alert(this.name);
};
function SubType(name, age) {
SuperType.call(this, name);
this.age = age;
}
SubType.prototype = new SuperType();
SubType.prototype.sayAge = function () {
alert(this.age);
}
var instance1 = new SubType("nicholas",29);
instance1.colors.push("black");
alert(instance1.colors);
instance1.sayName();
instance1.sayAge();
var instance2 = new SubType("greg", 28);
alert(instance2.colors);
instance2.sayName();
instance2.sayAge();
3.原型式继承
function object(o) {
function F(){}
F.prototype = o;
return new F();
}
var person = {
name:"nicholas",
friends:["sheny", "hony"]
}
var anotherperson = object(person);
anotherperson.name = "hoho";
anotherperson.friends.push("bob");
var yetanotherperson = object(person);
yetanotherperson.name = "fandy";
yetanotherperson.friends.push("goho");
alert(anotherperson.name);
alert(yetanotherperson.name);
alert(anotherperson.friends);
alert(yetanotherperson.friends);
或者object.create()
4.寄生式继承
function createAnother(original) {
var clone = object(original);
clone.sayHi = function () {
alert('hi');
}
return clone;
}
var person = {
name: "nicholas",
friends:["sheny", "hony"]
}
var anotherperson = createAnother(person);
anotherperson.sayHi();
5.寄生组合式继承
function inheritPrototype(subType, superType) {
var prototype = object(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
}
function SuperType(name) {
this.name = name;
this.colors = ["red", "blue", "green"];
}
SuperType.prototype.sayName = function () {
alert(this.name);
};
function SubType(name, age) {
SuperType.call(this, name);
this.age = age;
}
inheritPrototype(SubType, SuperType);
SubType.prototype.sayAge = function () {
alert(this.age);
}
第八章 BOM
窗口大小
innerWidth,innerHeight,outerWidth,outerHeight
转载于:https://juejin.im/post/5c91eac66fb9a070f1257992
javascript 高级程序设计(第三版)读后归纳相关推荐
- JavaScript高级程序设计第三版.CHM【带实例】
从驱动全球商业.贸易及管理领域不计其数的复杂应用程序的角度来看,说 JavaScript 已经成为当今世界上最流行的编程语言一点儿都不为过. JavaScript 是一种非常松散的面向对象语言,也是 ...
- javascript高级程序设计 第三版
网盘地址 提取码:vh81 笔记 第二章 2.1script标签 <script>元素属性:async.charset.defer.language.src.type async和defe ...
- JavaScript高级程序设计第三版 第3章 基本概念
第3章 基本概念 3.1 语法 3.1.1 区分大小写 3.1.2 标识符 3.1.3 注释 3.1.4 严格模式 3.1.5 语句 3.2 关键字和保留字 3.3 变量 3.4 数据类型 3.4.1 ...
- 10.1.2 Document类型【JavaScript高级程序设计第三版】
JavaScript 通过Document 类型表示文档.在浏览器中,document 对象是HTMLDocument(继承自Document 类型)的一个实例,表示整个HTML 页面.而且,docu ...
- 13.4.3 鼠标与滚轮事件【JavaScript高级程序设计第三版】
鼠标事件是Web 开发中最常用的一类事件,毕竟鼠标还是最主要的定位设备.DOM3 级事件中定义了9 个鼠标事件,简介如下. click:在用户单击主鼠标按钮(一般是左边的按钮)或者按下回车键时触发.这 ...
- DOM2和DOM3——JavaScript高级程序设计第三版第12章知识总结
DOM2和DOM3
- JavaScript高级程序设计第四版学习--第二十四章
title: JavaScript高级程序设计第四版学习–第二十四章 date: 2021-5-31 10:46:01 author: Xilong88 tags: JavaScript 本章内容: ...
- Js高级程序设计第三版学习(十二章)
Js高级程序设计第三版学习(十二章) 第十二章 DOM2和DOM3 1.样式: 访问样式属性 任何支持style特性的HTML元素都有一 ...
- JavaScript高级程序设计 第4版----String
JavaScript高级程序设计 第4版----String 文章目录 JavaScript高级程序设计 第4版----String 1.JavaScript 字符 2.字符串操作方法 1.conca ...
- JavaScript高级程序设计[第3版]
JavaScript高级程序设计[第3版] package xyz.huning.toolkit.pdf;import java.io.FileOutputStream; import java.io ...
最新文章
- android window 大小,android popupWindow 中宽度莫名很大,求帮助?
- bigqury 认证
- iptables命令结构之命令
- [置顶] 编写自己的JQUERY插件
- 介绍一下 information_schema 库
- 【NOIP2016】换教室
- julia有没有希望超越python_未来5-10年,Julia会替代Python成为量化投资热门语言吗?...
- ajax连接mysql数据库查询数据_ajax动态查询数据库数据并显示在前台的方法
- MPLS virtual private network Internet接入
- APACHE 在windows下的配置
- Springboot图片上传 百度ocr文字识别提取
- https请求,报错Could not establish trust relationship for the SSL/TLS secure channel
- 为什么我坚定看好分布式存储
- 论文笔记——News Recommendation with Topic-Enriched Knowledge Graphs
- ivms虚拟服务器,ivms监控服务器地址
- spring 启动日志报 DEBUG BeanNameUrlHandlerMapping:86 - Rejected bean name 'org.springframework.web.servl
- 【转载】HTML5新特性浅谈
- 布隆过滤器误判怎么办为什么会_五分钟小知识:布隆过滤器原理和应用分析
- 图说卡尔曼滤波(正在进行时)
- Java限流策略与算法