javascript总结

以下是网上看到的英文原版内容,我用自己的理解解释一下而已。

 

Functions are first-class objects.

函数是类对象的开始。例如 function classa(){this.a='a';} 就是一个类,里面有一个属性a。


Methods are just functions attached to objects.

方法只是附加到对象上的函数。就是说对象中的方法就是函数。感觉函数是万能的了,类和方法都是函数。


You can add methods to classes at any time (even after instances have been created).

你可以添加一个方法到一个类中,即使这个类的实例已经创建。也就是说你创建了一个类的实例后,再给这个类添加方法,则这个实例就立即有了这个方法。一点很奇特,有点像我熟悉的C#中的扩展函数。但这扩展得也太灵活了,任何时候任何地方都能扩展。


Individual objects can have their own methods.

单独的对象可以有其自己的方法。这个不用解释了


Class constructors'' are just functions.

类的构造函数只是一个函数。第一点的例子已经很明白了。


Functions, being objects, can have their own properties.

方法就是一个对象,有自己的属性。同上


You can call functions with fewer (or more) arguments than the function is declared to take.

你可以在调用方法时,使用的参数比方法中定义的多和少。少了好理解,后面的都是undefined,多了的话,函数内部使用argumetns去取,不取则无用而已。


If no value is passed for a function argument, it gets the value undefined.

如果没有值对应上函数的参数,则参数值为undefined。同上

原文地址:https://www.cnblogs.com/yvesliao/p/2581123.html