zoukankan      html  css  js  c++  java
  • js代码练习仓库

    String.prototype用于为某字符串对象新增方法,比如:

    String.prototype.replaceAll = function(oldStr, newStr) {
      return this.replace(new RegExp(oldStr,"gm"),newStr);
    }

    var a="dsdsdsadadasdad";

    a.replaceAll("a","c");
    "dsdsdscdcdcsdcd"

    var str1 = new String('haha');

    String.prototype.trim.call(str1);



    function Person(name, age) {
      this.name = name;
      this.age = age;
      this.alertName = function () {
        alert(this.name);
      }
      this.alertAge = function () {
        alert(this.age);
      }
    }

    var a=new Person();

    Person("dssd",90);

    alertAge();//90

    alertName();//dssd

    function webDever(name, age, sex) {

      //

      Person.call(this, name, age);

      this.sex = sex;

      this.alertSex = function () {

        alert(this.sex);

      }

    }

    
    
    String.prototype.say=function(){
    alert(this);
    };

    "test".say();




  • 相关阅读:
    前端工程化
    前端模块化CommonJS&ES6
    为什么浮点型运算结果会有误差?
    RequestAnimationFrame知多少?
    CSS三栏布局
    秋招面试
    实现Storage
    Angular
    TypeScript
    微服务架构设计模式
  • 原文地址:https://www.cnblogs.com/geekjsp/p/6734355.html
Copyright © 2011-2022 走看看