Giter VIP home page Giter VIP logo

learning_list's Introduction

你好,我是西了意 🌱

I'm currently learning:

  • JavaScript
  • TypeScript type system
  • React
  • stack based virtual machine

learning_list's People

Contributors

xxleyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

learning_list's Issues

Scheme things

一份完整的求解正数平方根的 scheme 程序,优雅到要人命。

(define (sqrt x)
  (define (improve guess)
    (average guess (/ x guess)))
  (define (average a b)
    (/ (+ a b) 2))
  (define (good-enough? guess)
    (< (abs (- (square guess) x)) 
       0.001))
  (define (try guess)
    (if (good-enough? guess)
        guess
        (try (improve guess))))
  (define (square a)
    (* a a))
  (try 1))

屏幕快照 2019-03-11 上午10 57 59
image

CS 61A Summer 2018 Lecture 03: Boolean Contexts

image

在动态语言 Python 中,条件语句会对跟随的表达式进行真假值检查,不只是 boolean 类型,所有类型的数据都有对应的真假值,即 true values or false values,not just True or False。

Beyond Closure in JS and Python

  • 演示语言为 JS 和 Python
  • 主题是闭包,但又不仅仅是闭包

大部分人对闭包的掌握程度:

能面试的程度
中级
我们用的插件里有用闭包的地方,如果我看源码,我能看出来

为啥有闭包?就是为了能在别的地方调用b函数用到函数a里的变量
a包着b

定场鸡汤

不要刻意去记住某件事,而要去寻找使其显而易见的解释。 -- 理查德·费曼


changA 不传参

let a = {a: 3}

function changeA(){
  a = {a: "change"}
  }
  
changeA()
a = {'a': 3}

def changeA():
  a = {'a': "change"}
  
changeA()

JS Tutor 小演示

Python3 Tutor 小演示

四种版本的二分查找算法

image

def bin_find_v1(v, lo, hi, e):
    if lo >= hi:
        return -1
    else:
        mi = (lo + hi) // 2
        if v[mi] == e:
            return mi
        if v[mi] > e:
            return bin_find_v1(v, lo, mi, e)
        else:
            return bin_find_v1(v, mi+1, hi, e)

v = [1, 2, 3, 4, 5, 6, 7]
bin_find_v1(v, 0, len(v), 3)

版本一:三个区间的二分查找,且头尾区间不均衡。
Python tutor 演示链接

JS prototype chain

代码主体来自同事大桃,我做了一些修改。😄😄😄

// 定义Person构造函数
function Person (name) {
    this.name = name
    this.sayHello = function(){
        console.log('hello from person')
    }
}

Person.prototype = new Person()
Person.prototype.constructor = Person
Person.prototype.sayName = function(){
    console.log(this.name)
}

// 定义Teacher构造函数
function Teacher (name,level){
    this.name = name
    this.level = level
}
Teacher.prototype = new Person()
Teacher.prototype.constructor = Teacher
Teacher.prototype.sayLevel = function(){
    console.log(this.level)
}

// 定义MathTeacher构造函数
function MathTeacher(name, level, className){
    this.name = name
    this.level = level
    this.className = className
}
MathTeacher.prototype = new Teacher()
MathTeacher.prototype.constructor = MathTeacher
MathTeacher.prototype.sayClassName = function (){
    console.log(this.className)
}

let liSi = new Person('Li Si')
let wangLaoShi = new Teacher('Wang Wu','Normal')
let zhangLaoShi = new MathTeacher('Zhang San','Great', 'Math')


console.log(liSi.hasOwnProperty("sayHello"))
console.log(wangLaoShi.hasOwnProperty("sayHello"))
console.log(zhangLaoShi.hasOwnProperty("sayHello"))

liSi.sayHello()
wangLaoShi.sayHello()
zhangLaoShi.sayHello()


liSi.sayName()
wangLaoShi.sayName()
zhangLaoShi.sayName()

wangLaoShi.sayLevel()
zhangLaoShi.sayLevel()

zhangLaoShi.sayClassName()

JS Tutor 演示

JS 中一些似是而非的概念

判等与隐式转换

  • ===:无隐式类型转换,情况少,基本满足判等需求(尤其是在自己手动转换类型的情况下)(推荐)
    • 原始类型与原始类型:当且仅当值与类型全相等时返回 true
    • 对象类型与对象类型:当且仅当两个变量为同一对象时返回 true
    • 原始类型与对象类型:一律为 false
  • ==:有隐式类型转换,情况特别多,虽然规则清晰,但是很难全部记住,轻易不要使用
    • 原始类型与原始类型:尤其注意 0 与 "" 以及 null == undefined => true
    • 对象类型与对象类型:当且仅当两个变量为同一对象时返回 true
    • 原始类型与对象类型:对象类型会调用 valueOf 或 toString

详细规则见 MDN

参考文档:You-Dont-Know-JS/ch4.md at 2nd-ed · getify/You-Dont-Know-JS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.