Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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.






                var name = 'window'

function Person (name) { = name
    this.obj = {
        name: 'obj',
        // 此时foo1,foo2的上层作用域为obj对象
        foo1: function () {
            return function () {
        foo2: function () {
            return () => {


var person1 = new Person('person1')
var person2 = new Person('person2')

person1.obj.foo1()() // window  (person1.obj.foo1()得到返回函数后直接调用,this指向全局对象) // window (还是直接调用,this指向全局对象)
person1.obj.foo1().call(person2) // person2 (person1.obj.foo1()这句话得到返回函数后,使用显示调用绑定person2,this指向person2)

person1.obj.foo2()() // obj (person1.obj.foo2()这句话得到返回函数后调用,但是箭头函数没有this,向上一层作用域找,上一层作用域为foo2函数,foo2是被obj对象调用的,所以this指向obj对象) // person2 (将foo2的上层作用域指向了person2,再进行调用的时候,上一层作用域就是person2)
person1.obj.foo2().call(person2) // obj (person1.obj.foo2()的到返回函数,使用显示绑定call无效,上一层作用域为foo2函数,foo2是被obj对象调用的,所以this指向obj对象)