一些Java面试题

来源:互联网 发布:南天软件待遇 编辑:程序博客网 时间:2024/05/16 18:09

1. JavaScript语言中的基本类型有哪些?
(1)number:包括正数、负数、小数
(2)string
(3)boolean:有true或false

**住:**JS中的数据类型
(1)基本数据类型
(2)复合数据类型:函数、对象、数组
(3)null、undefined

2. 写出JavaScript在IE和FireFox浏览器中的一些差异(至少写3条)

(1)添加事件
IE:element.attachEvent(”onclick”, func);。
FF:element.addEventListener(”click”, func, true)。
通用:element.onclick=func。虽然都可以使用onclick事件,但是onclick和上面两种方法的效果是不一样的,onclick只有执行一个过程,而attachEvent和addEventListener执行的是一个过程列表,也就是多个过程。例如:element.attachEvent(”onclick”, func1);element.attachEvent(”onclick”, func2)这样func1和func2都会被执行。

(2)标签的自定义属性
IE:如果给标签div1定义了一个属性value,可以div1.value和div1[“value”]取得该值。
FF:不能用div1.value和div1[“value”]取。
通用:div1.getAttribute(”value”)。

(3)父节点、子节点和删除节点
IE:parentElement、parement.children,element.romoveNode(true)。
FF:parentNode、parentNode.childNodes,node.parentNode.removeChild(node)。

(4)获取窗体的高度和宽度
IE:document.body.offsetWidth和document.body.offsetHeight。注意:此时页面一定要有body标签。
FF:window.innerWidth和window.innerHegiht,以及document.documentElement.clientWidth和document.documentElement.clientHeight。
通用:document.body.clientWidth和document.body.clientHeight。

5. JavaScript编程题:写一个Student类继承Person类的例子。对应的类图如下:

类图描述

JS继承方式:对象冒充

/***JS继承方式:对象冒充*/function Person(age, name){    this.age = age;    this.name = name;    this.sayHello = function(){    }}function Student(score, age, name){    this.newMethod = Person;    this.newMethod(age, name);    delete this.newMethod;    this.score = score;    this.sayScore = function(){    }}/***call*/function Person(age, name){    this.age = age;    this.name = name;    this.sayHello = function(){    }}function Student(score, age, name){    Person.call(this, age, name);    this.score = score;    this.sayScore = function(){    }}/***apply*可以把Student的整个arguments对象作为第二个参数传递给apply方法*当然,只有超类中的参数顺序与子类中的参数顺序完全一致才可以传递参数对象。*如果不是,就必须创建一个单独的数组,按照正确的顺序放置参数。此外,还可使用call方法。*/function Person(age, name){    this.age = age;    this.name = name;    this.sayHello = function(){    }}function Student(score, age, name){    Person.apply(this, age, name);    this.score = score;    this.sayScore = function(){    }}
0 0
原创粉丝点击