首页 > 其他分享 >使用Es6提供的构造函数Proxy实现数据绑定

使用Es6提供的构造函数Proxy实现数据绑定

时间:2023-01-08 00:12:33浏览次数:31  
标签:Es6 target strs indx value Proxy key receiver 构造函数

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  hello,world
  <input type="text" id="model">
  <p id="word">我是铁蛋儿</p>
  <!-- <script>
        const model = document.getElementById("model")
        const word = document.getElementById("word")


        const newObj = new Proxy({}, {
            get: function (target, key, receiver) {
                console.log(`getting ${receiver}!`);
                return Reflect.get(target, key, receiver);
            },
            set: function (target, key, value, receiver) {
                console.log('setting', target, key, value, receiver);
                if (key === "text") {
                    model.value = value;
                    word.innerHTML = value;
                }
                return Reflect.set(target, key, value, receiver);
            }
        });

        model.addEventListener("keyup", function (e) {
            newObj.text = e.target.value
        })
    </script> -->
  <script>
    function longestCommonPrefix(strs) {
      // write code here
      if (strs.length === 0 || strs === null) {
        return ""
      }
      let maxid = strs[0].length - 1;
      for (let i = 1; i < strs.length; i++) {
        var indx = -1; //下标flag
        while (indx < maxid && indx < strs[i].length - 1) {
          if (strs[0].charAt(indx + 1) === strs[i].charAt(indx + 1)) {
            indx++
          } else {
            break;
          }
        }
        if (indx === -1) {
          return ""
        }
        maxid = indx;
      }
      return strs[0].substring(0, maxid + 1);
    }

    console.log(longestCommonPrefix(["ab","abc","abca","abca", "abc", "abcc"]))





  </script>
</body>

</html>

 

标签:Es6,target,strs,indx,value,Proxy,key,receiver,构造函数
From: https://www.cnblogs.com/z-bky/p/17033915.html

相关文章

  • JavaScript学习笔记—构造函数
    执行流程:1.立刻创建一个新的对象2.将新建的对象设置为函数中的this,在构造函数中可以使用this来引用新建的对象3.逐行执行函数中的代码4.将新建的对象作为返回值返回通......
  • 区分CommonJs/ES6 Module/AMD/CMD
    模块加载方式CommonJsES6ModuleAMDCMDUMDCommonjs和ES6Module的区别总结1.CommonJSCommonJS是一个项目,其目标是为JavaScript在网页浏览器之外创建模块约......
  • Error occurred while proxying request localhost:端口 报错500的解决方法
    '/AuthServer/api/':{target:'https://localhost:44319',secure:false,//这是签名认证,http和https区分的参数设置changeOrigin:true,......
  • ES6语法糖,超甜!
    ES6语法糖1.......表示取出可遍历数组中的内容。constarr=newArray()constnumbers=[1,2,3,4,5]arr.push(...numbers)//arr内容:12345,即将numbers的内......
  • ES6笔记
    1、参考​​ECMAScript6简介​​2、…展开运算符/收集运算符​​ES6…展开&收集运算符​​​ES6之展开运算符(…)​​Es6(…)3、解构赋值解构赋值需要满足的条件:1、左......
  • ES6 arrow function and normal function difference
      watch(()=>data,()=>{drawChart()})//Uncaught(inpromise)ReferenceError:Cannotaccess'drawChart'beforeinitializationconstdrawChart=(......
  • c#的构造函数及构造函数的调用
    C#构造函数的特性一、什么是C#构造函数?Construct,Function   C#构造函数是一种特殊的成员函数,它主要用于为对象分配存储空间,对数据成员进行初始化.   C#构造......
  • Proxy
    Object.defineProperty缺陷:1.设计的初衷不是为了监听一个对象中的所有属性,初衷是定义普通的属性2.无法对新增属性、删除属性进行监听Proxy代理对象/*constp=n......
  • day01-ES6新特性
    ES6新特性1.ES6是什么?DCMAScript6.0(以下简称ES6)是JavaScript语言的下一代标准,2015年6月发布ES6设计目标:达到JavaScript语言可以用来编写复杂的大型程序,成为企业级......
  • 析构函数 和 构造函数 和 base使用
    classA//基类First{~A()//析构函数{Console.WriteLine("~A()析构函数");}publicA(){......