js的类调用

类对象:ClassB

let ClassB =
{    
    ClassName:'ClassB',
    GetName()
    {
        alert(1);    
    }
}

export default ClassB;

 

调用:ClassA

import ClassB from './ClassB.js'

ClassB.GetName();
    
//document.getElementById('root').value = ClassB.ClassName;

 

页面:Html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

</head>
<body>
<input id='root' />

<script src="js/ClassB.js" type="module"></script>
<script src="js/ClassA.js" type="module"></script>
</body>
</html>

 

posted @ 2022-05-14 07:08  阿日斯兰  阅读(202)  评论(0编辑  收藏  举报