FCC-Object Oriented and Functional Programming

在Basic JavaScript当中我们学习了JS最基本的语法,对于已经有过Java背景的同学来说,应该没有什么不能接受的地方,唯独JS的数据结构比较松散,自由罢了。接下来学一些面向对象的JS基本以及一些JS中数组的函数和String的函数。
1. 创建对象的时候除了字面量表示法,还可以:We are also able to create objects using constructor functions. A constructor function is given a capitalized name to make it clear that it is a constructor. Here’s an example of a constructor function:

```
var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};
var myCar = new Car();
// Note that it is important to use the new keyword when calling a constructor. This is how Javascript knows to create a new object and that all the references to this inside the constructor should be referring to this new object.
```

2. We used the this keyword to reference public properties of the current object. We can also create private properties and private methods, which aren’t accessible from outside the object. To do this, we create the variable inside the constructor using the var keyword we’re familiar with, instead of creating it as a property of this.
3. The map method will iterate through every element of the array, creating a new array with values that have been modified by the callback function, and return it. Note that it does not modify the original array.
4. filter is passed a callback function which takes the current value (we’ve called that val) as an argument.Any array element for which the callback returns true will be kept and elements that return false will be filtered out.
5. You can use the method sort to easily sort the values in an array alphabetically or numerically. Sort can be passed a compare function as a callback. The compare function should return a negative number if a should be before b, a positive number if a should be after b, or 0 if they are equal. If no compare (callback) function is passed in, it will convert the values to strings and sort alphabetically.
6. You can use the reverse method to reverse the elements of an array. reverse is another array method that alters the array in place, but it also returns the reversed array.
7. We can split a String into an arrayor join elements in an array into a String.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值