Giter VIP home page Giter VIP logo

js's Introduction

题目1
function Parent() {
    this.a = 1;
    this.b = [1, 2, this.a];
    this.c = { demo: 5 };
    this.show = function () {
      console.log(this.a , this.b , this.c.demo);
    }
  }
  function Child() {
    this.a = 2;
    this.change = function () {
      this.b.push(this.a);
      this.a = this.b.length;
      this.c.demo = this.a++;
    }
  }
  Child.prototype = new Parent();
  var parent = new Parent();
  var child1 = new Child();
  var child2 = new Child();
  child1.a = 11;
  child2.a = 12;
  parent.show();
  child1.show();
  child2.show();

  child1.change();
  child2.change();
  parent.show();
  child1.show();
  child2.show();
题目2
function Foo() {
    getName = function () { alert (1); };
    return this;
}
Foo.getName = function () { alert (2);};
Foo.prototype.getName = function () { alert (3);};
var getName = function () { alert (4);};
function getName() { alert (5);}
 
//请写出以下输出结果:
Foo.getName();
getName();
Foo().getName();
getName();
new Foo.getName();
new Foo().getName();
new new Foo().getName();
题目3
var A = function() {
    this.name = 'apple';
}
A.prototype.getName = function() {
    return this.name;
}

// 补充代码

var B = A.extend({
    initialize: function() {
        this.superclass.initialize.call(this);
        this.total = 3;
    },
    say: function() {
        return '我有' + this.total + '个' + this.getName()
    }
});
var b = new B();
console.log(b.say()); //我有3个apple
题目4
const HardMan = (name) => {
class HardMan {
	contructor (name) {
		this.tasks = [this.init(name)]
		setTimeout(async () => {
			for (const task of this.tasks) {
				await task()
			}
		}, 0)
	}
	init (name) {
		return () => console.log(`I am ${name}`)
	}

	sleep (time) {
		return () => new Promise(
			resolve => setTimeout( () => {
				resolve(console.log(`Start learning after ${time} seconds` ))
			}, time * 1000),
		)
	}
	rest (time) {
		this.tasks.push(this.sleep(time))
		return this
	}
	restFirst (time) {
		this.tasks.unshift(this.sleep(time))
		return this
	}
	learn (skill) {
		this.tasks.push(() => {
			console.log(`Learning ${sth}`)
		})
		return this
	}
	return new HardMan(name)
}

}

js's People

Contributors

anjorn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.