Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div id="result"></div>




                const result_dom = document.getElementById('result');
result_dom.innerHTML = '';

interface IPhoneCharger {
    chargeWith3Footer(): void;

// Target
interface PrimaryCharger {
    chargeWith2Footer(): void;
// adaptee 
// 苹果手机实现苹果手机充电器接口
class IPhone implements IPhoneCharger {
  chargeWith3Footer() {
      result_dom.innerHTML += "苹果手机开始充电啦~~~🔋";

// adapter
// 普通充电器适配器 - 实现普通充电器接口 - 使苹果手机等其他充电器可以适配普通2脚充电器进行充电
class PrimaryChargerAdapter implements PrimaryCharger {
    private phone: any;
    constructor(phone: any) { = phone;
    chargeWith2Footer(): void {
        if ( === IPhone) {
          // 适配器在这里适配三脚和二脚充电器接口

function TestDemo() {
    const iPhone = new IPhone();
    // iPhone.chargeWith2Foot(); // Uncaught TypeError: iPhone.chargeWith2Foot is not a function
   // 中国大陆一般都是2插口插座~需要使用2脚充电器充电 chargeWith2Footer(),
   // 但是苹果手机是三脚充电器不支持~~
    // 通过充电器适配器,实现了chargeWith2Footer(),符合客户期望的接口~~~
    const adaptedIPhone = new PrimaryChargerAdapter(iPhone);
    adaptedIPhone.chargeWith2Footer(); // 完美~~