<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script> const claPrice = (function(){
const sale = {
"800": (price) => price -= 700, "200": (price) => price -= 100, "10%": (price) => price *= 0.1, } function claPrice(price,type) {
if(!sale[type]) return "没有这个折扣"; return sale[type](price); } claPrice.add = function(type,fn) {
if(sale[type]) return "该折扣已经存在"; sale[type] = fn; return "添加成功"; } claPrice.remove = function(type) {
delete sale[type]; } return claPrice; }()) claPrice.add("20%",(price) => price *= 0.2); claPrice.remove("20%"); console.log(claPrice(1000,"20%")); </script>
</body>
</html>