闭包

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // let a = 89;
  12. // let b = 86;
  13. // let c = 90;
  14. // function sum(b, a) {
  15. // //内部变量
  16. // return b + a + c;
  17. // }
  18. // console.log(sum(29, 344));
  19. function demo1() {
  20. let email = "80883341@qq.com";
  21. return function child() {
  22. return email;
  23. };
  24. }
  25. alert(demo1()());
  26. // function demo2() {
  27. // let a = "2121";
  28. // }
  29. // alert(demo2);
  30. </script>
  31. </body>
  32. </html>

遍历数组

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. let colors = ["red", "blue", "green"];
  12. for (i = 0; i < colors.length; i++) {
  13. console.log(colors[i]);
  14. }
  15. </script>
  16. </body>
  17. </html>

静态方法

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 无需实例化(new)直接使用类名.方法调用
  12. class Users {
  13. constructor(name, email) {
  14. this.name = name;
  15. this.email = email;
  16. }
  17. show() {
  18. return {
  19. names: this.name,
  20. emails: this.email,
  21. age: this.#age,
  22. };
  23. }
  24. static fetch() {
  25. return this.UserName;
  26. return this;
  27. return "static+++++function";
  28. }
  29. //私有成员
  30. #age = 50;
  31. // 静态变量
  32. static UserName = "灭绝诗美";
  33. // 访问器属性:伪装成属性的方法 有get set
  34. get age() {
  35. return this.#age;
  36. }
  37. }
  38. const Account = new Users();
  39. console.log(Account.show());
  40. console.log(Users.#age);
  41. console.log(Users.age);
  42. // console.log(Users.fetch());
  43. // console.log(Users.UserName);
  44. </script>
  45. </body>
  46. </html>

类与继承

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // function User(name, pass) {
  12. // this.name = name;
  13. // this.pass = pass;
  14. // this.show = function () {
  15. // return { name: this.name, email: this.email };
  16. // };
  17. // }
  18. // const user = new User("kowal", "kowalpass");
  19. // console.log(user);
  20. function User(name, pass) {
  21. this.name = name;
  22. this.pass = pass;
  23. // this.show = function () {
  24. // return {
  25. // name: this.name,
  26. // email: this.email,
  27. // };
  28. // };
  29. }
  30. User.prototype.show = function () {
  31. return { name: this.name, pass: this.pass };
  32. };
  33. const user = new User("kowal", "mima");
  34. console.log(user);
  35. console.log(user.show());
  36. const user1 = new User("pter", "jmvnnnnn");
  37. console.log(user1);
  38. console.log(user1.show());
  39. </script>
  40. </body>
  41. </html>

原型

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // function f1() { // return "eeee"; // } alert(f1());
  12. // 任何一个函数都是对象,都有一个共通属性【prototype】
  13. // 何为原型:原型=父盒,提供原始参数,子元素可以继承父元素的原型属性
  14. //函数作为基本函数使用时 prototype属性基本无用,但依然作为函数的初始化属性
  15. // 当一个函数作为构造函数使用时,必须使用“new”关键字进行区别
  16. // 通过构造函数创建对象的过程为 对象实例化
  17. // 对象实例化后的对象可以看作为一个类
  18. //建立函数
  19. function User() {
  20. name = "kowal";
  21. ID = 80887765;
  22. pass = '90872udhn"';
  23. }
  24. // 当成普通函数进行调用;
  25. const user = User();
  26. // console.log(user);
  27. console.dir(user);
  28. // *******??当成构造函数调用 此时需用new关键字********
  29. const xcv = new User();
  30. console.dir(xcv);
  31. </script>
  32. </body>
  33. </html>

对象

  1. <!-- <!DOCTYPE html> -->
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. class User1 {
  12. constructor(name, email) {
  13. this.name = name;
  14. this.email = email;
  15. }
  16. show() {
  17. return {
  18. name_show: this.name,
  19. email_show: this.email,
  20. };
  21. }
  22. get age() {
  23. return this.age;
  24. }
  25. #age = 50;
  26. }
  27. const Account1 = new User1("天彭老师", "80883341@qq.com");
  28. const Account2 = new User1("kowal", "5677765@qq.com");
  29. // console.log(Account);
  30. // console.log(typeof Account);
  31. // console.log(typeof User1);
  32. // console.log(Account.show());
  33. console.log(Account2.age());
  34. // console.log(Account2.show());
  35. // console.log(Account1.show());
  36. </script>
  37. </body>
  38. </html>

函数作用域

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 函数作用域
  12. let site = "PHPCN"; //全局site变量
  13. function getSite() {
  14. let site = "JDSC"; //函数内site变量
  15. return site;
  16. // 函数作用域查询的过程中,就拿site变量为例,查询中先以自身作用域内做检查,如果用site变量则返回该值,如果检查不到该变量则继续向外查询
  17. // 如果最后查不到该site变量那么提示undefind 未定义 这个过程叫做作用域链
  18. let domain = "baidu.com"; //私有变量,domain变量为内部变量,仅限于作用域内访问外部不可调用
  19. }
  20. // alert(getSite());
  21. alert(getSite());
  22. </script>
  23. </body>
  24. </html>

while循环

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // const colors = ["red", "grenn", "blue"];
  12. // let j = 0;
  13. // while (j < colors.length) {
  14. // j++;
  15. // console.log(colors[j]);
  16. // }
  17. // 对象遍历 For-IN
  18. // const OBJEC = {
  19. // name: "kowal",
  20. // phone: "13082899878",
  21. // shooe: "Nike",
  22. // ID: 988898,
  23. // };
  24. // for (let xh in OBJEC) {
  25. // console.log(OBJEC[xh]);
  26. // }
  27. for (let i = 0; i <= 100; ) {
  28. console.log(i);
  29. i++;
  30. }
  31. </script>
  32. </body>
  33. </html>

更多相关文章

  1. js基础知识:变量与常量,函数及参数
  2. 第 84 天:NumPy 数学函数
  3. 不产生第三个临时变量的前提交换两组数据
  4. js之留言板与数组字符串函数
  5. JavaScript 之 作用域和闭包,类的继承
  6. 210401 JavaScript 值传递与引用传递, 模板字面量, 标签函数, 解
  7. 【JS基础入门】JavaScript中创建对象的7种创建模式
  8. 作用域与闭包;类与类的继承
  9. 第126天:Seaborn-可视化统计关系

随机推荐

  1. 老艿艿说:关于时间管理的分享
  2. 分布式作业系统 Elastic-Job-Lite 源码分
  3. 如何使用Python实现FTP服务器?Python学习
  4. CentOS7 上搭建多节点 Elasticsearch集群
  5. 分布式做系统 Elastic-Job-Lite 源码分析
  6. yarn-site.xml的部分资源配置参数,主要是
  7. 注册中心 Eureka 源码解析 —— 任务批处
  8. 分布式作业系统 Elastic-Job-Cloud 源码
  9. 分布式作业 Elastic-Job-Lite 源码分析
  10. VMWare 添加新磁盘,并挂载