"JavaScript has first class functions, which allows us to treat functions as data — assign them to variables, pass them to other functions, return them from functions, etc…" This is totally bullshit, seems so called "functions" in Javascript are just class objects.
n*p
4 楼
First class里的此class非彼class
as functions, just
【在 s*****w 的大作中提到】 : "JavaScript has first class functions, which allows us to treat functions as : data — assign them to variables, pass them to other functions, : return them from functions, etc…" : This is totally bullshit, seems so called "functions" in Javascript are just : class objects.
r*z
5 楼
如果没有内部的状态,没有副作用,你何必在乎是如何实现的呢?
as functions, just
【在 s*****w 的大作中提到】 : "JavaScript has first class functions, which allows us to treat functions as : data — assign them to variables, pass them to other functions, : return them from functions, etc…" : This is totally bullshit, seems so called "functions" in Javascript are just : class objects.
s*w
6 楼
我知道那句话是说functions是一等公民,但它的function不就是简化过的class吗?
【在 n***p 的大作中提到】 : First class里的此class非彼class : : as : functions, : just
s*w
7 楼
我是从OOP过来的,读着js不舒服, 觉得很乱
【在 r*****z 的大作中提到】 : 如果没有内部的状态,没有副作用,你何必在乎是如何实现的呢? : : as : functions, : just
n*p
8 楼
why thinking function is 简化过的class? It's the other way around, class is data and functions combo, which is unnecessary and usually class data are mutable, they are the root cause for many concurrent programming issues.
lisp keeps data and functions seperated, and it is easier for purer FP languages like clojure to deal with concurrent programming. javascript or other oop+fp hybrid languages are not the best language to learn FP.
data and functions combo, 这又有啥问题? 如果是数学公式,我完全支持FP。 但这世界是由object构成的,家里前门是红色的,这个红色就是data,就跟这扇门联系 在一起,有啥问题?
is
【在 n***p 的大作中提到】 : why thinking function is 简化过的class? It's the other way around, class is : data and functions combo, which is unnecessary and usually class data are : mutable, they are the root cause for many concurrent programming issues. : : lisp keeps data and functions seperated, and it is easier for purer FP : languages like clojure to deal with concurrent programming. : javascript or other oop+fp hybrid languages are not the best language to : learn FP.
yes, red is data, and it is not a function, you are mixing up oop with object. They are not the same. oop is about encapsulation, inheritance, and polymorphism, which all these so called great features are useless(see my last post) for FP, the pure FP language can do all OOP design patterns so easily and naturally.
【在 s*****w 的大作中提到】 : data and functions combo, 这又有啥问题? : 如果是数学公式,我完全支持FP。 : 但这世界是由object构成的,家里前门是红色的,这个红色就是data,就跟这扇门联系 : 在一起,有啥问题? : : is
谢谢大家的讨论,我的问题不清楚是因为我没有理解。 目前是这样的,我们组写Javascript ES6坚决不肯用class,就像你们说的把function 传来传去,也许我们用法不对,我们写common interface时没有base class, 基本就是 2个js文件当作2个derived class, 里面有很多一样名字的function而已, 不像以前有 c++ has class hierarchy, 有个专门的base class. 然后我去读 https://stackoverflow.com/questions/30783217/why-should-i-use-es6-classes 有个人分别用ES6 class, ES5 function写了2个例子,我硬是看不出有啥区别,除了 class更清晰易懂。
【在 n***p 的大作中提到】 : yes, red is data, and it is not a function, : you are mixing up oop with object. They are not the same. : oop is about encapsulation, inheritance, and polymorphism, which all these : so called great features are useless(see my last post) for FP, the pure FP : language can do all OOP design patterns so easily and naturally.
In oop, person三围变了,it is same person. It's not the case for FP like clojure, it's not the same person if 三围 changes. You think "正常"的思路, 在clojure programmer眼里不正常,we like to deal with immutable object all the time.
property
【在 s*****w 的大作中提到】 : 这个我是同意的。 : 但另一方面,生活中闲聊某个人,她身高三围,有工作吗?会做菜吗?这样把property : and function bind together是非常正常的思路。
n*p
36 楼
That's why I said hybrid languages are not good for learning fp. Scala at least let you pick between val and var, JavaScript obj almost always mutable.
【在 n***p 的大作中提到】 : That's why I said hybrid languages are not good for learning fp. : Scala at least let you pick between val and var, JavaScript obj almost : always mutable. : : function