js之外的语言探究

C语言

  1. int main(void) /* 该chunk名为main,返回一个int值,参数为空void,意味着没有参数,main作为函数名比较特殊,默认以main函数为入口,永远要有一个main
  2. 数据类型有:short、int、long、char、float、double以及void
  3. 指针可以用来加减,作者不负责任猜测:设指针类型对应的字节数为n,指针增加x后,指向的地址会增加xn字节。
  4. 数组变量中存储的是第0项的指针;string实际上是char[]
  5. 结构体是用户自定义的结构,基于各种基础类型。js中的对象大概就是一个指向结构体的指针。
  6. struct s {int attr;}; struct s ins; struct s *ptr = &ins则ptr->attr 相当于js中的ptr.attr

java

  1. 三种局部变量:methods, constructors, blocks 块级作用域在js中比较少见
  2. 实例变量: 当class初始化时被declare,该类的Method可访问之。
  3. 类变量:类中声明的变量(区别呢?)
  4. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.
  5. The public class name should be the name of the source file
  6. Access Modifier : public protected(可被subclass访问) private(只能被该class访问) 以及默认
  7. static: 在静态方法中不能访问类的非静态成员变量和非静态成员方法,因为非静态成员方法/变量都是必须依赖具体的对象才能够被调用。
  8. 静态方法,就是和类挂钩的方法: ClassName.method.用类名访问
  9. 常量池:据说声明的常量(比如数字、字符串)会在编译时进入常量池,包括常量拼凑出的常量,这导致一些同值的常量变量==为true,而 new出的String则是运行时确定的。
  10. 实例方法equals对于每个类有不同的定义,比如String的equal就是比较两个字符串序列每一个char是否一样。考虑这个情况:String a = “sometxt”; String b = new String(“sometxt”); a == b返回false,而a.equals(b)返回true

python

  1. 用dir(className)查询类方法,用help(className.methodName)查询api
  2. [ (x if x > 2 else 1) for x in range(1,5)]
  3. 用type(obj)来查看类型

你可能感兴趣的:(C,语言,c语言,语言)