An Object Oriented Programming Object oriented JS () Overview

1. What is the object orientation is?

Just a programming idea

2. The object-oriented programming features - Package

1) built-in objects: Bom objects, dom objects, String, Math, Array

2) custom objects:

3. The object-oriented and process-oriented differences :

Is a process, is a target

4. Object-oriented benefits:

① closer to real everyday life events

② can not control the function of the specific implementation, directly call the object's methods

3) greatly improve the readability of code reusability and maintainability

<script>
    //在控制台打印字符ch1 在字符串str1中的位置,如果没有找到就返回-1
    var  ch1 = 'd';
    var str = 'abcdef';
    for(var i=0;i<str.length;i++){
        if(str.charAt(i)==ch1){
              console.log(i);
               break;
        }
    }
    
    if(i==str.length){
        console.log(-1);
    }    

//封装起来变成一个函数
function indexOf(ch1,str){
    for(var  i = 0;i<str.length;i++){
        if(str.charAt(i)==ch1){
                 return i;
        }
           
    }
return -1;
}

//截取字符串中的某一段字符串
function subString(){
}

//查看字符串是否以某个字符串结尾
function  endWidth(){
}

//js定义一个对象
var String = new Object();
</script>

https://tool.lu/coderunner/   

https://tool.css-js.com/coderun.html    the code online editor

Published 98 original articles · won praise 4 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_42416812/article/details/100103718